linux - SCTP RCVBUF 在 Linux 中设置不正确

标签 linux sctp

我试图将 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/

相关文章:

c++ - 错误: ‘ ’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

macos - SCTP 在 OSX 上缺少包含文件?

c - SCTP多宿主

c++ - SCTP recvmsg返回EFAULT(错误地址)

c - 如何编辑 sctp.h 以添加 SO_REUSEADDR

mysql - 如何从 linux 文件中删除特定符号?

linux - Valgrind ARM 二进制文件在 ARM926EJ 中不工作,给出错误未找到

linux - 在 Linux 上维护一个长时间运行的任务

linux - 寻找在服务器机器启动时启动新 tmux 部分的方法

sockets - 关闭对 SCTP 套接字的调用是阻塞还是非阻塞?