in reply to Waiting for input, without sleep

From cpan IO::Socket::SSL :

peek(...)

This function has exactly the same syntax as sysread(), and performs nearly the same task (reading data from the socket) but will not advance the read position so that successive calls to peek() with the same arguments will return the same results. This function requires OpenSSL 0.9.6a or later to work.


pending()

This function will let you know how many bytes of data are immediately ready for reading from the socket. This is especially handy if you are doing reads on a blocking socket or just want to know if new data has been sent over the socket.


Update:
Fixed cpan link. ikegami++

Replies are listed 'Best First'.
Re^2: Waiting for input, without sleep
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 15:44 UTC
    Neither of these work, it doesn't wait for input from the server at all.... $sock->peek($sock, $response, 4000);
      Yes, peek() and pending() are intended as non-blocking calls that you can use to get an idea of what will happen if you issue a read().

      If I understand your question correctly, you desire a more efficient way to wait until the response from the server is available. This is typically done by:
      while($data = $sock->peek()){ if($data eq $what_you_want){ &DO_YOUR_STUFF; last; }else{ sleep 1; } }

      It's not totally necessary to have that short sleep, but typically you want some type of pause so that your script doesn't get into a tight loop and hog the cpu.

      If you don't know what data you expect back, you can use pending() instead of peek() to see the amount of data waiting to be read().
        Hrm. For some reason Peek keeps giving me "0" and it falls out if the while loop right away:

        while($response = $sock->peek()) { if ($response ne '') { #verify the data print "Server Response: $response\n"; $response = (string2hex($response)); print "Server Response: $response\n"; last; } else { sleep 1; print "Waiting for a response!\n"; } }