Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Dec 2003 17:39:16 -0500
From:      Yaoping Ruan <yruan@cs.princeton.edu>
To:        hackers@freebsd.org, freebsd-current@freebsd.org
Subject:   select() in 5.X
Message-ID:  <3FECB894.54922CA6@cs.princeton.edu>

next in thread | raw e-mail | index | archive | help
Not sure if somebody here has already noticed this problem before. I
have a small program using select() . Though it works correctly on 4.x,
some problem happens on 5.1. First of all, I notice that macros about
FD_xx have been moved into sys/select.h. Then FD_ZERO() seems to be
failed. My program looks like follow:

main( )
{ ...
fd_set rfdset;

FD_ZERO(&rfdset);

....
}

Replace the macro of FD_ZERO with the definition in sys/select.h and
then running GDB reveals the following information:

(gdb) print rfdset
$2 = {__fds_bits = {1874, 635, 0, 0, 1327, 2173, 288, 2299, 0, 1923, 95,
1980,
    1844, 1510, 2063, 2327, 1371, 0, 317, 227, 957, 0, 0, 1285, 0, 2339,
1817,
    2090, 1460, 341, 2306, 1298}}
(gdb) print n
$3 = 2047
(gdb) print (&rfdset)->__fds_bits[2047]
Cannot access memory at address 0xbfc01644

So the problem is that when rfdset is defined, it only got 32 elements.
But when FD_ZERO is executed, the "howmany(...)" function gives out 2048
elements. This function is defined exactly the same in the above two
cases, as:
((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS))

I think there's something I missed. Could someone help this out? Thanks

- Yaoping





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FECB894.54922CA6>