Why is my sysread Perl block reading from a socket?
I am doing sysread in Perl 5.8.2 on AIX 5.3. According to the documentation, sysread
should give 0 when it has read everything read from the file descriptor.
In my scenario, the file descriptor is STDIN and points to a socket. So I mostly do sysread
from socket. But I never get 0 from sysread
and it just blocks, even after the client has sent all the data.
Any idea what could be wrong?
Thank.
source to share
What does "sent all data" mean? sysread
returns zero when the descriptor encounters an end-of-file condition, not when there is no data available right now. For a socket, an EOF on read occurs when the other side disconnects the socket for writing. (Well, sysread
it will also return undef
, which is numerically zero if an error occurs, such as a network timeout.)
source to share