select(2) is just a hint (Was: Re: [Twisted-Python] ENOBUF and Twisted)

Tommi Virtanen tv at twistedmatrix.com
Fri Aug 20 03:30:21 EDT 2004


Andrew Bennetts wrote:
> Well, the problem is that currently the select reactor assumes that if
> select says a socket is writeable, then it is writeable, i.e it is safe to
> attempt to write any amount of data to it (with the understanding that being
> non-blocking it might only be able to accept some of that data immediately).
> Apparently this assumption is not quite accurate.

That's not a safe assumption under UNIX. select(2) is just a hint; writing
to the socket may still give you EAGAIN, even if select(2) said it's writable.
And the same goes for reading, too.

For the reason why this must be allowed, think about a non-blocking fd shared
between two processes:

	Process 1			Process 2
	select() says fd 4 writable
					select() says fd 4 writable
	write(4, ...) success
					write(4, ...) = -1, EAGAIN

But this isn't the only case when select is unable to predict the future;
as soon as your code _must_ support the above case in order to work, the
kernel can use that feature of the API to make some socket bookkeeping
things easier.




More information about the Twisted-Python mailing list