Implementation of select - A design question.

Implementation of select - A design question.

Post by chin.. » Wed, 20 Oct 1999 04:00:00



Hello:

    I am just curious about the implementation of the FD macros and
select function in UNIX systems.

    The select call returns the number of fds set in the fd_set
specified in the call. Wouldnt it be more useful to the application if
it got an array of fds that are ready. This will be useful when I am
using select with many descriptors. Right now the flow of a program
waiting to read on 100 descriptors will be like.

1) Add the 100 descriptors to the read fd_set.
2) Call select.
3) Call FD_ISSET on 100 descriptors to see if they are set. (This is
the worst estimate).

If on the other hand select returned an array of set descriptors the
steps would be

1) Add 100 descriptors to the read fd_set
2) Call select
3) Use the return value of select.

  Any comments will be welcome. Just trying to understand the design of
the internals of the UNIX os.

Cheers....

Chinmay V. P.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Implementation of select - A design question.

Post by Tomasz Omiecinsk » Thu, 21 Oct 1999 04:00:00


Have a look at <sys/types.h> for definitions of fd_set and the FD_XXX macros
(well, at least they are macros on HP-UX 10.20, but the man pages generally
say they might as well be functions you should not assume anything :)).

What you'll find there should make you realise that in fact select returns
what you want and you're not constrained to FD_ISSET on each descriptor, but
can process the sets them as you like and are prepared to implement :).

Hope this solves the issue.

Regards,
Tom


> Hello:

>     I am just curious about the implementation of the FD macros and
> select function in UNIX systems.

>     The select call returns the number of fds set in the fd_set
> specified in the call. Wouldnt it be more useful to the application if
> it got an array of fds that are ready. This will be useful when I am
> using select with many descriptors. Right now the flow of a program
> waiting to read on 100 descriptors will be like.

> 1) Add the 100 descriptors to the read fd_set.
> 2) Call select.
> 3) Call FD_ISSET on 100 descriptors to see if they are set. (This is
> the worst estimate).

> If on the other hand select returned an array of set descriptors the
> steps would be

> 1) Add 100 descriptors to the read fd_set
> 2) Call select
> 3) Use the return value of select.

>   Any comments will be welcome. Just trying to understand the design of
> the internals of the UNIX os.

> Cheers....

> Chinmay V. P.

> Sent via Deja.com http://www.deja.com/
> Before you buy.


 
 
 

1. Design Question select and threads

 I have a server that accepts connection on a port.  Once a connection is
 accepted a client object is created to represent that connection.  The
 object is put in a list and the file descriptor (fd) is put in a select
 structure.  When the select command returns I go through the list and
 process which ever objects are readable.  Right now this is all ran in one
 thread.  I would like to have multiple threads servicing these clients.  I
 was thinking of having one thread be the master and then when clients
become
 readable they get put in a list which worker threads deal with and the fd
is
 taken out of the select group.  When the command of the client is finished
 being processed the client is put back in the original list, fd put back in
 the select group.  To make it so that the select will register the newly
 added fd I have a special fd  that wakes it up and then puts it right back
 to sleep waiting for a client to be readable again.  Is this how
programmers
 usually handle this situation or is there a better way to do it.

2. Xterm Problems w/ kernel 1.3.8

3. Call for Papers - 5th Symposium on Operating Systems Design and Implementation (OSDI 2002)

4. Bookmark Merge Program?

5. Call for Papers - 5th Symposium on Operating Systems Design and Implementation (OSDI 2001)

6. Fonts under X

7. CFP: Operating Systems Design and Implementation (1st OSDI)

8. NYC LOCAL: Monday 12 November 2001 NYLUG Meeting: Eric S. Raymond on Decentralism against Terrorism

9. 2nd Symposium on Operating Systems Design & Implementation (OSDI)

10. OSDI, the 5th Symposium on Operating Systems Design and Implementation

11. dll design and implementation

12. Call for Papers - 5th Symposium on Operating Systems Design and Implementation (OSDI 2002)