Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my Perl sysread block when reading from a socket?

Tags:

sockets

perl

I m doing a sysread in Perl 5.8.2 on AIX 5.3. As per the documentation, sysread is supposed to give 0 when it has read all read from filehandle.

In my scenario, the filehandle is STDIN and points to a socket. So I m basically doing a sysread from a socket. But I never get 0 from sysread and it just blocks, even after client has sent all data.

Any idea what might be wrong?

Thanks.

like image 609
someguy Avatar asked Dec 02 '25 19:12

someguy


2 Answers

What do you mean "sent all data"? sysread returns zero when the handle encounters an end-of-file condition, not when there's no more data available right now. For a socket, EOF on read occurs when the other side has shutdown the socket for write. (Well, and sysread will also return undef, which is numerically equal to zero, if an error occurs such as a network timeout.)

like image 117
hobbs Avatar answered Dec 04 '25 07:12

hobbs


Check out the select command (the one with the 4 arguments). It can tell you whether there is any input to be read on your filehandle.

like image 45
mob Avatar answered Dec 04 '25 09:12

mob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!