Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #2018

Re: select() on a write pipe in the readfds set works?

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.unix.programmer
Subject Re: select() on a write pipe in the readfds set works?
Date 2012-02-06 01:49 +0000
Organization Freie Universitaet Berlin
Message-ID <9p8pu7FgglU1@mid.uni-berlin.de> (permalink)
References <2012020516294132323-znqbxn@alnavfberarg>

Show all headers | View raw


Julian Hsiao <znqbxn@alnavfber.arg> wrote:
> I'd expect EBADF or some other error from select(), or is this 
> undefined behavior? select()ing a read pipe in the writefds set works, 
> too. Aren't pipes unidirectional (on Linux and OS X anyway)?

I've not gone through your program in detail but regarding the
question if you shouldn't get a EBADF if you put a read-only
file descriptor into the write set of a select() call (or a
write-only descriptor into the read set) I would think that
EDADF here just means that it's not a "valid" file descriptor
in the sense that there's no open file descriptor with that
number, but not that it's a file descriptor unsuitable for
a certain purpose.

At least in SUS4 there's a difference in the wording between
what EBADF is described to mean for e.g. read(), where it says

  The fildes argument is not a valid file descriptor open for reading.

(so you're guaranteed that trying to read on a file opened only
for writing will make read() fail with EBADF) and what it says
for select():

  One or more of the file descriptor sets specified a file descriptor
  that is not a valid open file descriptor.

Now, a file opended for writing is per se a "valid" open file
descriptor, just not suitable for reading. And that isn't chan-
ged by the fact that it will never be possible to read from it,
thus select() never will return due to it becoming readable.

Thus I think that a system that doesn't flag an EBADF error
for calling select() with a file descriptor opened only for
reading in the write set is conforming to the POSIX standard.

                             Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.unix.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

select() on a write pipe in the readfds set works? Julian Hsiao <znqbxn@alnavfber.arg> - 2012-02-05 16:29 -0800
  Re: select() on a write pipe in the readfds set works? jt@toerring.de (Jens Thoms Toerring) - 2012-02-06 01:49 +0000
    Re: select() on a write pipe in the readfds set works? Julian Hsiao <znqbxn@alnavfber.arg> - 2012-02-05 21:15 -0800

csiph-web