select + write edge cases

Dirk Koopman djk at
Mon Jan 8 14:07:13 GMT 2007

On Mon, 2007-01-08 at 13:29 +0000, Nicholas Clark wrote:
> On Mon, Jan 08, 2007 at 01:12:27PM +0000, Dirk Koopman wrote:
> > I have a select handler working on (I try to set as) non blocking
> > sockets ($sock->blocking(0)). I select on output (carefully enabling and
> > However, it still manages to hang in __write_nocancel() (in my perl
> > 5.8.8) on output when the operating system buffer for that socket.
> > The impression I am getting is that, even when a queue is full, select
> > may drop saying "output available" and then when I syswrite(), it hangs
> > instead of returning 0.
> Odd. If it's really a non blocking socket then surely that syswrite should
> return EGAIN, even if the select has lied.

That is what I am expecting. It is well known that select can lie on
'read' and I get EAGAIN when I do the sysread() (or at least I have
never caught it hanging on reading - yet). Certainly EAGAIN is returned
on an "empty" read if I do this all in C. 

> But (say) select and syswrite are both getting their "it's ready to write"
> from the same source, and that source is lieing, then this behaviour is
> consistent with that. But I've no idea if this happens.
> What OS? (Not that this will really help me, but it might help others)

I believe this is happening on both Linux (2.6) and windows.


More information about the mailing list