[Israel.pm] receiving undef via socket

Roie Marianer roiem at actcom.co.il
Fri Aug 4 02:17:00 PDT 2006

> I have an application that is forking clients and talks to them via
> sockets. Ocassionally the client receives undef via the socket. I wonder
> why.
Never worked with Unix sockets before, so I may be way off here, but... is the 
<$sock_to_parent> call in the child nonblocking? Perhaps the child tries to 
read from the parent before the parent finishes writing to the socket, and 
instead of waiting, you get undef.

Also, depending on the circumstances, you may get a partial command 
(especially if the command was very long, but I believe the operating system 
is technically allowed to split even a two-byte message), or two commands (if 
they were short and submitted in rapid succession).

Basically, you seem to be treating a stream-based socket as if it were a 
datagram-based socket, and as you just found out, that doesn't always 
work. :-)

At least, that's my experience with TCP, maybe it's different with Unix 


More information about the Perl mailing list