Erick
Erick

Reputation: 752

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?

Upvotes: 2

Views: 2126

Answers (2)

Gilimanjaro
Gilimanjaro

Reputation: 391

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

Upvotes: 3

Robert Gamble
Robert Gamble

Reputation: 109052

Set the Blocking option to 0 when creating the socket:

$sock = IO::Socket::INET->new(Blocking => 0, ...);

Upvotes: 9

Related Questions