加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

在做一个set后,getsockopt SO_RECVBUF在linux中显示了两倍的值?

发布时间:2020-12-14 00:30:15 所属栏目:Linux 来源:网络整理
导读:当使用SO_RECVBUF调用setsockopt时,然后转向并使用SO_RECVBUF调用getsockopt,它似乎告诉我它将缓冲区大小设置为我要求它设置的两倍.有人知道为什么会这样吗? 有问题的代码: https://gist.github.com/rdp/8443238 输出: setting it as 2222[udp @ 0x1a72ec
当使用SO_RECVBUF调用setsockopt时,然后转向并使用SO_RECVBUF调用getsockopt,它似乎告诉我它将缓冲区大小设置为我要求它设置的两倍.有人知道为什么会这样吗?

有问题的代码:

https://gist.github.com/rdp/8443238

输出:

setting it as 2222
[udp @ 0x1a72ec0] end receive buffer size reported is 4444

仅在linux中,在其他操作系统上似乎将其报告为我设置的值.
谢谢.

解决方法

插座摘自 Linux man page

SO_SNDBUF

Sets or gets the maximum socket send 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/wmem_default file and the maximum allowed value is
set by the /proc/sys/net/core/wmem_max file. The minimum (doubled)
value for this option is 2048.

因此,内核将为内部目的设置的值加倍.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读