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.

+2


source to share


2 answers


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.)



+5


source


Check select

(the one that has 4 arguments). It can tell you if there is any input to read in your file descriptor.



+2


source







All Articles