SCTP RCVBUF is not set properly in Linux

2019-06-05 16:57发布

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;

标签: linux sctp
1条回答
霸刀☆藐视天下
2楼-- · 2019-06-05 17:23

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.

查看更多
登录 后发表回答