views:

128

answers:

2

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?

+6  A: 

Set the Blocking option to 0 when creating the socket:

$sock = IO::Socket::INET->new(Blocking => 0, ...);
Robert Gamble
File this one under 'RTFD... correctly'
Erick
+2  A: 

Checkout IO::Select; it's very often what I end up using when handling sockets in a non-blocking way.

Gilimanjaro