Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Nov 1998 12:53:43 -0500
From:      Bakul Shah <bakul@torrentnet.com>
To:        Nate Williams <nate@mt.sri.com>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Supporting more than FD_SETSIZE fd's 
Message-ID:  <199811141753.MAA25077@chai.torrentnet.com>
In-Reply-To: Your message of "Wed, 11 Nov 1998 12:03:08 MST." <199811111903.MAA18067@mt.sri.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > The code fragment I showed is approx. right as I've used
> > something similar a couple of times before but I will try to
> > turn it into a working example over the weekend.

> Thanks.  If it included the MACROS so much the better. :) :) :)

Check out
    http://www.bitblocks.com/src/select-test.c
It even includes code to create and manipulate an FD set
object!  Note that when used on a kernel that has fixed
FD_SETSIZE select() implementation, you must allocate exactly
FD_SETSIZE elements (and certainly no less) in an FD set.

BTW, instead of my FD_xxx functions you can use bitstring
macros from /usr/include/bitstring.h.

Sample use:

In window 1:

1307% cc select-test.c
1308% ./a.out 1234
accepting on 1234, fd_setsize = 1024
3: accept from 127.0.0.1:28681
4: open
3: accept from 127.0.0.1:28937
5: open
4: Sat Nov 14 12:14:45 EST 1998
4: close
5: Sat Nov 14 12:14:46 EST 1998
5: close
^C
1309%

In Window 2:

852% (sleep 3 ; date)| telnet 1234&
853% (sleep 3 ; date)| telnet 1234&
854%

This is a sample program and hence it is missing a few
obvious optimizations, error checking, as well as code to
deal with timeouts, write and exception FD_sets etc.  In a
program for real use, you would likely put all fds in
nonblocking mode; you would have multiple accept fds (one per
interface); in do_accept() you would accept all outstanding
connections; in do_read() you would read everything the other
side sends (or not, depending on any fairness criterion); you
would likely keep an array of functions, indexed by a fd, for
a quick dispatch; and so on.

For any moderately complex processing you may be better off
using pthreads than a select loop (unless you want to squeeze
out the very last drop of performance without descending to
assembly language code).

-- bakul

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811141753.MAA25077>