Thursday, March 3, 2011

How can I read from an IO::Socket::INET filehandle only if there is a complete line?

When reading from a IO::Socket::INET filehandle it can not be assumed that there will always be data available on the stream. What techniques are available to either peek at the stream to check if data is available or when doing the read take no data without a valid line termination and immediately pass through the read?

From stackoverflow
  • Set the Blocking option to 0 when creating the socket:

    $sock = IO::Socket::INET->new(Blocking => 0, ...);
    
    Erick : File this one under 'RTFD... correctly'
  • Checkout IO::Select; it's very often what I end up using when handling sockets in a non-blocking way.

0 comments:

Post a Comment