Re: Question on select() and sockets
- From: Alex Fraser <me@xxxxxxxxxxx>
- Date: Sat, 07 Jun 2008 09:25:12 +0100
William Ahern wrote:
K-mart Cashier <cdalten@xxxxxxxxx> wrote:[snip]
Perhaps I'm not thinking this through, but how
"This all sounds fine. But you must set the pipes non-blocking else
you
can still end up blocking, even if you only call read() or write()
after
select() says the descriptor is, respectively, readable or writeable:
Is this possible?
For pipes the scenario would probably involve another process or thread
invalidating the condition.
I don't know of an implementation where read() can block after select() says a pipe descriptor is readable, but as you described there is at least one real-world implementation where this is not true for sockets. I (amongst others) believe the implemented behaviour is standards-compliant, but it seems that some people disagree with this interpretation.
However, the final issue I mentioned - that you don't know how many bytes you can write without blocking - seems quite clear to me. The descriptor for a socket is bidirectional, and both directions are normally used, so the issue of whether it is allowed for readability to be retracted is basically moot: write()/send() must be non-blocking, and handling the possibility that you get EAGAIN/EWOULDBLOCK on read()/recv() is surely preferable to setting/unsetting O_NONBLOCK around every write()/send() call.
Alex
.
- Follow-Ups:
- Re: Question on select() and sockets
- From: Rainer Weikusat
- Re: Question on select() and sockets
- References:
- Question on select() and sockets
- From: K-mart Cashier
- Re: Question on select() and sockets
- From: Alex Fraser
- Re: Question on select() and sockets
- From: K-mart Cashier
- Re: Question on select() and sockets
- From: William Ahern
- Question on select() and sockets
- Prev by Date: Question on Deamons
- Next by Date: Re: Question on select() and sockets
- Previous by thread: Re: Question on select() and sockets
- Next by thread: Re: Question on select() and sockets
- Index(es):
Relevant Pages
|
Loading