in reply to Listening without forking

I've heard before that the Event module is the way to go... I've not played with it, but I have tried out IO::Select, and it seemed worthy.

IO::Select runs as an event loop blocking on the select() command until any specified handly (typically any read handle) handles become 'active' by having data available. you can perform non-blocking reads with this quite well, so the only time the server is blocking is when nothing is happening, or when it is actively getting data from a buffer, which is a fast operation.

needless to say this causes other intereseting problems in coding, like dealing with data when it is more likely than not incomplete from the non-blocking read... but things like timeouts should be much less of a problem.

Replies are listed 'Best First'.
Re: Re: Listening without forking
by zengargoyle (Deacon) on Feb 24, 2002 at 02:11 UTC

    In the Event Tutorial (maybe POD doc) there was mention of the blocking problem, recommendation was IPC::LDT or similar. Use messages that include the total length at the beginning of the message.

    read SOCK, $len_raw, 4; $len = unpack 'N', $len_raw; read SOCK, $msg, $len; and $len = length $msg; $len_raw = pack 'N', $len; write SOCK, $len_raw, 4; write SOCK, $msg, $len; or write SOCK, "$len_raw$msg", $len+4;

    Something like that should handle the simple cases.