在Linux中未正确设置SCTP RCVBUF [英] SCTP RCVBUF is not set properly in Linux

查看:297
本文介绍了在Linux中未正确设置SCTP RCVBUF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将RCVBUF设置为1MB//1048576,但是在尝试通过getsockopt读取它时设置了该值之后,它始终将其值设置为2MB//2097152 谁能告诉我下面的代码是什么问题?

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;

推荐答案

以下是man 7 socket关于SO_RCVBUF选项的内容:

Here is what is said in man 7 socket regarding SO_RCVBUF option:

SO_RCVBUF

设置或获取最大套接字接收缓冲区(以字节为单位). 内核将这个值加倍(以保留簿记空间 开销)(使用setsockopt(2)进行设置),并且此值增加了一倍 由getsockopt(2)返回.默认值由 /proc/sys/net/core/rmem_default文件,最大允许值为 由/proc/sys/net/core/rmem_max文件设置.最小(加倍) 此选项的值是256.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆