套接字缓冲区的大小没有增加 [英] Socket buffer size not increasing

查看:132
本文介绍了套接字缓冲区的大小没有增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int n = 0;
if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n)))
{
    printf("Get socket option failed, errno: %d\n",errno);
}
else
{
    printf("Current socket buff len = %d\n", n);
}
n = 225280;
if(0 != setsockopt(iSockFd, SOL_SOCKET, SO_RCVBUF, (const void *)&n, sizeof(n)))
{
    printf("setsock err errno %d\n", errno);
}
else
{
    printf("setsock opt success\n");
}
n = 0;
if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n)))
{
    printf("Get socket option failed, errno: %d\n",errno);
}
else
{
    printf("After setting socket buff len = %d\n", n);
}

输出为-

当前套接字buff len = 41600

Current socket buff len = 41600

setsock选择成功

setsock opt success

设置套接字增益后len = 41600.

After setting socket buff len = 41600.

好像接收缓冲区的大小没有增加,为什么会这样呢?

Looks like receive buffer size is not increasing, any idea why this happens?

提前谢谢!

推荐答案

如果内核是较新的版本(2.6.17或更高版本),请通过验证文件/proc/sys/net/ipv4/来检查是否启用了自动调整tcp_moderate_rcvbuf.如果tcp_moderate_rcvbuf的值为1,则启用自动调整.在这种情况下,接收缓冲区将由内核动态更新,并绑定到/proc/sys/net/ipv4/tcp_rmem中的值.检查是否达到此限制.

If the kernel is of newer version (2.6.17 or higher), checkout whether autotuning is enabled by verifying the file /proc/sys/net/ipv4/tcp_moderate_rcvbuf . If the value of tcp_moderate_rcvbuf is 1, then autotuning is enabled. In such a scenario, the receive buffer will be dynamically updated by the kernel and is bound to the values in /proc/sys/net/ipv4/tcp_rmem. Check whether this limit is hit.

如果内核是旧版本,请检查SO_RCVBUF是否受/proc/sys/net/core/rmem_default和/proc/sys/net/core/rmem_max中的值限制. 如果是TCP,还请检查/proc/sys/net/ipv4/tcp_rmem

If the kernel is of older version, check whether the SO_RCVBUF is limited by the values in /proc/sys/net/core/rmem_default and /proc/sys/net/core/rmem_max. Incase of TCP, also check the value of /proc/sys/net/ipv4/tcp_rmem

还请注意,使用setsockopt()手动调整套接字缓冲区大小会禁用自动调整".这是有关调整Linux的很好的链接 http://www.psc.edu /index.php/networking/641-tcp-tune

Also note that 'Manually adjusting socket buffer sizes with setsockopt() disables autotuning' . Here is good link on tuning for linux http://www.psc.edu/index.php/networking/641-tcp-tune

这篇关于套接字缓冲区的大小没有增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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