SCTP RCVBUF is not set properly in Linux

浪尽此生 提交于 2019-12-08 04:32:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!