Re: Question on select() and sockets



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
.



Relevant Pages

  • Re: how to return from a blocked read() ?
    ... It doesn't matter. ... it's blocking, it's in the read. ... That thread can use that descriptor... ... on some of your posts. ...
    (comp.os.linux.development.apps)
  • Re: how to return from a blocked read() ?
    ... It doesn't matter. ... it's blocking, it's in the read. ... I'll be opening another file descriptor ... that unrelated connection but it can also cause the original thread to ...
    (comp.os.linux.development.apps)
  • Re: select() question, avoiding blocks on read/write
    ... avoid IO blocking. ... A descriptor shall be considered ready for reading when a call ... of multiple descriptors at the same time, ...
    (comp.unix.programmer)
  • Re: threads vs. processes
    ... A call to an input function with O_NONBLOCK clear means a blocking ... standard doesn't intend that in the definition of "block". ... It says that a descriptor in blocking ... Given that page faults can happen when an input function is called on ...
    (comp.unix.programmer)
  • Re: Question on select() and sockets
    ... can still end up blocking, even if you only call reador write ... If it's a listening socket, ... If it's a UDP socket for readability, ...
    (comp.unix.programmer)

Loading