select() in 5.X

From: Yaoping Ruan <yruan_at_cs.princeton.edu>
Date: Fri, 26 Dec 2003 17:39:16 -0500
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
Received on Fri Dec 26 2003 - 13:41:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:35 UTC