mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: select() - Linux vs. BSD
@ 2001-06-01  8:16 Andries.Brouwer
  2001-06-01 16:38 ` lost
  0 siblings, 1 reply; 14+ messages in thread
From: Andries.Brouwer @ 2001-06-01  8:16 UTC (permalink / raw)
  To: dean-list-linux-kernel, jcwren; +Cc: linux-kernel


    On Tue, 29 May 2001, John Chris Wren wrote:

    >     In BSD, select() states that when a time out occurs,
    >     the bits passed to select will not be altered.
    >     In Linux, which claims BSD compliancy for this
    >     in the man page (but does not state either way
    >     what will happen to the bits), zeros the users bit masks
    >     when a timeout occurs.

(i) "In BSD" - which one did you look at? 4.2? 4.3? 4.4?
Details differ a bit.

(ii) The Linux man page only says

RETURN VALUE
       On  success,  select  and  pselect  return  the  number of
       descriptors contained in the descriptor sets, which may be
       zero  if  the  timeout expires before anything interesting
       happens.  On error, -1  is  returned,  and  errno  is  set
       appropriately;  the  sets and timeout become undefined, so
       do not rely on their contents after an error.
	
That is, a wise programmer does not assume any particular value
for the bits after a timeout.

    >     Should the man pages be changed to reflect reality,

They do reflect reality.

    > or select() fixed to act like BSD?

No, select() is fine.


dean gaudet answered:

    sounds like a man page bug.

Shame on him for noticing man page bugs without cc'ing
the man page maintainer! Fortunately however, I do not
think anything is wrong here. But just to be sure I added
a sentence to select.2:

  On BSD, when a timeout occurs, the file descriptor bits are not changed.
  Linux follows SUSv2 and sets the bit masks to zero upon a timeout.

Andries

^ permalink raw reply	[flat|nested] 14+ messages in thread
* RE: select() - Linux vs. BSD
@ 2001-06-03  2:47 John Chris Wren
  2001-06-03  3:31 ` Mike Castle
  2001-06-03  7:52 ` David Schwartz
  0 siblings, 2 replies; 14+ messages in thread
From: John Chris Wren @ 2001-06-03  2:47 UTC (permalink / raw)
  To: linux-kernel


>
> lost@l-w.net wrote:
> > Of course, not looking at the sets upon a zero return is a
> fairly obvious
> > optimization as there is little point in doing so.
>
> No; a fairly obvious optimisation is to avoid calling FD_ZERO if you
> can clear the bits individually when you test them.
>
> When you examine the sets, you can clear each bit that you examine and
> then you know you have a zero set.  Then you can set only the relevant
> bits for the next call to select().
>
> If you can't rely on the sets being cleared on a timeout, then you
> will have to call FD_ZERO in that case, or you will have to go through
> the list of descriptors and clear them individually.  (This can be
> avoided but it means keeping track of state between successive calls
> to select()).  This is contrary to the non-timeout case, where you
> stop checking bits when you have counted N of them set.
>
> So you see, there is a handy optimisation if you can assume the sets
> are zeroed on timeout.
>

I would have said just the opposite.  That if it you have a large number of
handles you're waiting on, and you have to go back through and set the bits
everytime you timeout that you would incur a larger overhead.  From the
perspective of my application, it would have been more efficient to not zero
them (I was waiting on a number of serial channels, and the timeout was used
to periodically pump more data to the serial channel.  When I received data,
I buffered it, and another thread took care of processing it).

It all really depends on the coding style of your program, and what you need
to do on a timeout.  Certain types of applications would benefit from
non-zero'ing, others from zeroing.

All what is *most* important is that the behavior is clearly understood and
well documented.  A google search made it pretty clear that it was a source
of confusion.

--John


^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: select() - Linux vs. BSD
@ 2001-06-01 17:33 Andries.Brouwer
  0 siblings, 0 replies; 14+ messages in thread
From: Andries.Brouwer @ 2001-06-01 17:33 UTC (permalink / raw)
  To: Andries.Brouwer, lost; +Cc: dean-list-linux-kernel, jcwren, linux-kernel

> So how does this say the value of the fdsets are undefined
> after a timeout?

You are right, it doesn't say so. I should have said
  That is, a wise programmer does not assume any particular value
  for the bits after an error.

Andries

^ permalink raw reply	[flat|nested] 14+ messages in thread
* select() - Linux vs. BSD
@ 2001-05-29 15:55 John Chris Wren
  2001-05-29 17:34 ` Mike Castle
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: John Chris Wren @ 2001-05-29 15:55 UTC (permalink / raw)
  To: linux-kernel

	I hope I'm not rehashing anything discussed before, but I couldn't find any
references to this:

	In BSD, select() states that when a time out occurs, the bits passed to
select will not be altered.  In Linux, which claims BSD compliancy for this
in the man page (but does not state either way what will happen to the
bits), zeros the users bit masks when a timeout occurs.  I have written a
test case, and run on both systems; BSD behaves as stated, Linux does not
act like BSD.

	Should the man pages be changed to reflect reality, or select() fixed to
act like BSD?

	-- John


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2001-06-03  7:52 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-01  8:16 select() - Linux vs. BSD Andries.Brouwer
2001-06-01 16:38 ` lost
2001-06-02 21:46   ` Jamie Lokier
2001-06-03  2:13     ` lost
  -- strict thread matches above, loose matches on Subject: below --
2001-06-03  2:47 John Chris Wren
2001-06-03  3:31 ` Mike Castle
2001-06-03  7:52 ` David Schwartz
2001-06-01 17:33 Andries.Brouwer
2001-05-29 15:55 John Chris Wren
2001-05-29 17:34 ` Mike Castle
2001-05-29 19:51 ` Alan Cox
2001-05-29 20:50   ` lost
2001-05-29 21:06 ` dean gaudet
2001-05-31  1:40 ` Dr. Kelsey Hudson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®