For server side programming I use the listen function as: int listen(int sockfd, int backlog);
I understand that the backlog should be less than or equal to the somaxconn set on the host system where I would run my server program. If I use SOMAXCONN as the backlog, it will be equivalent to hard-coding it to the value of SOMAXCONN that is usually defined in tcp.h as 128.
However, somaxconn is a tunable sysctl parameter, that can be modified by changing the value of /proc/sys/net/core/somaxconn or by using sysctl to modify net.core.somaxconn
People usually modify somaxconn to attain better system performance. I would like my program to take advantage by evaluating the system's somaxconn, at the time when the program was started.
I could open the file /proc/sys/net/core/somaxconn and read the contained value, but it seems quite an inelegant way of doing things, specially because I think that the filepath to somaxconn may vary, depending upon the distro.
Is there an API or sample code, that allows evaluating the somaxconn, in c/c++ ?
Also tell me if I am missing some crucial point, leading to flawed thinking.
I also want to port my application to Windows, so Windows programmers may also have some useful insights to share!
Thanks in advance, to all fellow hacks.