我试图将 RCVBUF 设置为 1MB//1048576 ,但是当我尝试通过 getsockopt 读取它时设置值后它总是给出 2MB//2097152 的值 谁能告诉我以下代码有什么问题?
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;
最佳答案
这是 man 7 socket
中关于 SO_RCVBUF 选项的内容:
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.
关于linux - SCTP RCVBUF 在 Linux 中设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11826377/