Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing FD_SETSIZE

Tags:

select

glibc

I need to increase the FD_SETSIZE value from 1024 to 4096. I know it'd be better to use poll()/epoll() but I want to understand what are pros/cons. The main question is: have I to recompile glibc? I read several thread where the change of .h after changing FD_SETSIZE works recompiling only the user application. Reading the glibc code (and the kernel too), actually it seems to me that if I want to use select(), FD_* macro and so on, I have to recompile all because the size of fd_set is changed. At this point I have to recompile all not only my application because if in the system there is an another "common" application that uses select and friends, I could have problem. Am I right?

like image 301
user1633717 Avatar asked Nov 04 '22 15:11

user1633717


1 Answers

Technically, you do not have to recompile glibc. It would be sufficient to use come up with your own version of <sys/select.h> that has a larger fd_set_t, but is otherwise compatible. It will magically work because the select function receives the largest file descriptor (plus one), so it can figure out the set sizes. The other functions and macros are either inline or do not care about the actual set size.

It's still a bad idea, so you really should be using poll or epoll instead.

In the past, some libcs supported defining FD_SETSIZE before including <sys/select.h> to obtain a larger set size, but I don't think support for that was ever part of mainline glibc.

like image 86
Florian Weimer Avatar answered Nov 09 '22 10:11

Florian Weimer