🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
2 messages
2 total messages Started by SIMON RADEMACHER Tue, 18 Aug 1992 04:20
select() broken?
#1200
Author: SIMON RADEMACHER
Date: Tue, 18 Aug 1992 04:20
47 lines
2914 bytes
Hopefully, this should be easy, but perhaps a bit dull--no graphics
nor even Objective C here.

We've developing a suite of programs here that use tcp sockets for
communications.  Select() is used to multiplex communications.  Everything
goes ok until one program disconnects from another. Then, select() in the
second program never detects any furthur events on any file descriptors,
including ones that it was detecting events on before the disconnect.
So, does select() have a bug?

Here's a more complete description of what happens with one of the programs:
1) The program opens three tcp socket services and one client. The client
   successfully connects.
2) It then does a select() in the main loop.  It uses a timeout in the
   select() so that it can do other, clock-based work.  The timeout has
   ranged from 100 microseconds to over 1 second with the same results.
3) The select() correctly identifies connection requests on the services
   as well as data arriving on the client.  When a connect request is
   seen, an accept() is done, and the new fd is added to the read fd_set.
4) Data arriving on the newly accepted fd is noted and read.
5) When one of the accepted fd's disconnects, the read fd_set shows an
   event on the fd.  A read is done resulting in EOF.  The fd is closed()
   and removed from the read fd_set.
6) From then on, the select() always waits for the duration of the time-
   out, and returns 0, eg. no events in any of the sets.

Note, the following possible causes have been checked.
a) The read fd_set IS rebuilt before each select() call.  The except fd_set
   is also built and is the same set as the read.  The write fd_set is set
   to NULL 'cause I don't care about writes.  Although the except is sent to
   select(), any exceptions are currently ignored.  (Shouldn't be a problem,
   right?)
b) The number of fds select() should look at (nfds) is larger than the
   greatest fd number.
c) The socket fd given from socket() is not closed, just the fd given by
   the accept call.

Another program behaves similarly, but includes stdin in the read fd_set
for user input.  When it looses its client connection, it also ignores
input on other inputs, including stdin.

Any clues?  Oh, BTW, this occures on 2.1 and 3.0PR2.
Thanks in advance for any help.
-- 
Simon Rademacher
rademach@alumni.cs.colorado.edu
Re: select() broken?
#1209
Author: SIMON RADEMACHER
Date: Tue, 18 Aug 1992 23:42
28 lines
1854 bytes
In article <1992Aug18.042006.12768@colorado.edu> rademach@alumni.cs.colorado.edu (SIMON RADEMACHER) writes:
[summary: select() did not see events on file descriptors after one
 disconnected.]
>
>5) When one of the accepted fd's disconnects, the read fd_set shows an
>   event on the fd.  A read is done resulting in EOF.  The fd is closed()
>   and removed from the read fd_set.
OOPS----^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I lied. The array used to mark active file descriptors was cleared of the
disconnected fd. Hence, in the loop, the bit was not being set for that
fd, but it remained set from the previous go through the loop. Actually
clearing the bit fixes the problem.

6) From then on, the select() always waits for the duration of the time-
>   out, and returns 0, eg. no events in any of the sets.

Hmm, that fixes the problem, but is this a bug? When the bit for
a just close()d file is in the read fd_set, select() does not see any
events on any file descriptors. I would guess that if any invalid fd were
in the set the same thing would happen.  So, whether select() is broken
or not depends on if you think select() should be smart enough to ignore
invalid/closed fds.

In any case, thanks to those who sent mail with help.

-- 
Simon Rademacher
rademach@alumni.cs.colorado.edu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads