问题
I am trying to set RCVBUF to 1MB//1048576 , But after setting the value when I am trying to read it through getsockopt it always gives the value as 2MB//2097152 could anyone let me know what is the problem with the below code?
unsigned int rcvBuf = getRcvBufValue();
if (setsockopt (channelfd, SOL_SOCKET, SO_RCVBUF, &rcvBuf,sizeof (rcvBuf)) == -1)
{
cout<<"RCV BUF IS NOT SET";
}
int rcvbuf = -1;
socklen_t Rsize = sizeof(rcvbuf);
getsockopt (channelfd, SOL_SOCKET, SO_RCVBUF,&rcvbuf,&Rsize);
cout<<rcvbuf;
回答1:
Here is what is said in man 7 socket
regarding SO_RCVBUF option:
SO_RCVBUF
Sets or gets the maximum socket receive buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using setsockopt(2), and this doubled value is returned by getsockopt(2). The default value is set by the /proc/sys/net/core/rmem_default file, and the maximum allowed value is set by the /proc/sys/net/core/rmem_max file. The minimum (doubled) value for this option is 256.
来源:https://stackoverflow.com/questions/11826377/sctp-rcvbuf-is-not-set-properly-in-linux