Skip to contentSkip to conversation

fd_setsize

DISCUSSION [email protected] 2 participants 2 messages Dec 14, 2001

lore
Share & tools
lore
#0 lore raw

hi,

I am using 2.4 kernel. How can I increase the fd_setsize so that I can use select to check more than 1024 file descriptors?

thanks,

hui

#1 lore raw

In article <[email protected]>,

Quoted 2 lines · <[email protected]> wrote:

I am using 2.4 kernel. How can I increase the fd_setsize so that I can use select to check more than 1024 file descriptors?

That's more a glibc question. On many systems, you can set FD_SETSIZE before including <sys/select.h> and the libs will use that FD_SETSIZE from that point on.

With glibc, you can't do that. Well that's not entirely true, the following works but is not portable and an unbelievable hack.

BTW, why not use poll() - it has no fd_set imposed limit.

BTW2 don't forget to increase the ulimit filedescriptor max, and perhaps /proc/sys/fs/{file-max,inode-max}

/*
* Cannot increase FD_SETSIZE on Linux, but we can increase __FD_SETSIZE
* with glibc 2.2 (or later? remains to be seen). We do this by including
* bits/types.h which defines __FD_SETSIZE first, then we redefine
* __FD_SETSIZE. Ofcourse a user program may NEVER include bits/whatever.h
* directly, so this is a dirty hack!
*/
#include <features.h>
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)

#    include <bits/types.h>
#    undef __FD_SETSIZE
#    define __FD_SETSIZE 8192

#endif

Mike.

Signature · 2 lines
Deadlock, n.:
        Deceased rastaman.