compile-fan
compile-fan

Reputation: 17625

Where's the const SOMAXCONN defined in c?

I thought it was retrieve at compile time from /proc/sys/net/core/somaxconn,but after I modified it to 1024 by echo 1024 > /proc/sys/net/core/somaxconn,the SOMAXCONN is still 128 in my programe.

    printf("---------------set socket to listen,maxconn is %d--------------\r\n\r\n", SOMAXCONN);
    // set socket to listen
    if (listen(sock_listen, SOMAXCONN) != 0)...

I've checked sys/socket.h but it's not there...

Where/how can I change its value?

Upvotes: 0

Views: 6195

Answers (2)

Paul R
Paul R

Reputation: 212969

Under Linux it seems to be here:

$ find /usr/include -name \*.h -exec grep SOMAXCONN {} /dev/null \;
/usr/include/bits/socket.h:#define SOMAXCONN    128

Under Mac OS X and BSD it seems to be here:

$ find /usr/include -name \*.h -exec grep SOMAXCONN {} /dev/null \;
/usr/include/sys/socket.h:#define   SOMAXCONN   128

i.e. in both cases it's socket.h but they live in different locations on different operating systems it seems.

Upvotes: 3

Piotr Praszmo
Piotr Praszmo

Reputation: 18320

On my system it's defined in bits/socket.h

/* Maximum queue length specifiable by listen.  */
#define SOMAXCONN   128

According to this, you don't need to use SOMAXCONN. Just specify number you want and it will be limited to actual maximum.

Upvotes: 3

Related Questions