int n = 0; if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n))) { printf("Get socket option failed, errno: %dn",errno); } else { printf("Current socket buff len = %dn", n); } n = 225280; if(0 != setsockopt(iSockFd, SOL_SOCKET, SO_RCVBUF, (const void *)&n, sizeof(n))) { printf("setsock err errno %dn", errno); } else { printf("setsock opt successn"); } n = 0; if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n))) { printf("Get socket option failed, errno: %dn",errno); } else { printf("After setting socket buff len = %dn", n); }
Output is –
Current socket buff len = 41600
setsock opt success
After setting socket buff len = 41600.
Looks like receive buffer size is not increasing, any idea why this happens?
Thanks in advance!
Advertisement
Answer
If the kernel is of newer version (2.6.17 or higher), checkout whether autotuning is enabled by verifying the file /proc/sys/net/ipv4/tcp_moderate_rcvbuf . If the value of tcp_moderate_rcvbuf is 1, then autotuning is enabled. In such a scenario, the receive buffer will be dynamically updated by the kernel and is bound to the values in /proc/sys/net/ipv4/tcp_rmem. Check whether this limit is hit.
If the kernel is of older version, check whether the SO_RCVBUF is limited by the values in /proc/sys/net/core/rmem_default and /proc/sys/net/core/rmem_max. Incase of TCP, also check the value of /proc/sys/net/ipv4/tcp_rmem
Also note that ‘Manually adjusting socket buffer sizes with setsockopt() disables autotuning’ . Here is good link on tuning for linux http://www.psc.edu/index.php/networking/641-tcp-tune