linux网卡缓冲区设置,【Linux】tcp缓冲区大小的默认值、最大值

Author:阿冬哥

Created:2013-4-17

Blog:http://blog.csdn.net/c359719435/

Copyright 2013 阿冬哥 http://blog.csdn.net/c359719435/

使用以及转载请注明出处

1 设置socket tcp缓冲区大小的疑惑

疑惑1:通过setsockopt设置SO_SNDBUF、SO_RCVBUF这连个默认缓冲区的值,再用getsockopt获取设置的值,发现返回值是设置值的两倍。为什么?

通过网上查找,看到linux的内核代码/usr/src/linux-2.6.13.2/net/core/sock.c,找到sock_setsockopt这个函数的这段代码:

case SO_SNDBUF:

/* Don't error on this BSD doesn't and if you think

about it this is right. Otherwise apps have to

play 'guess the biggest size' games. RCVBUF/SNDBUF

are treated in BSD as hints */

if (val > sysctl_wmem_max)//val是我们想设置的缓冲区大小的值

val = sysctl_wmem_max;//大于最大值,则val值设置成最大值

sk->sk_userlocks |= SOCK_SNDBUF_LOCK;

if ((val * ) < SOCK_MIN_SNDBUF)//val的两倍小于最小值,则设置成最小值

sk->sk_sndbuf = SOCK_MIN_SNDBUF;

else

sk->sk_sndbuf = val * ;//val的两倍大于最小值,则设置成val值的两倍

/*

* Wake up sending tasks if we

* upped the value.

*/

sk->sk_write_space(sk);

break;

case SO_RCVBUF:

/* Don't error on this BSD doesn't and if you think

about it this is right. Otherwise apps have to

play 'guess the biggest size' games. RCVBUF/SNDBUF

are treated in BSD as hints */

if (val > sysctl_rmem_max)

val = sysctl_rmem_max;

sk->sk_userlocks |= SOCK_RCVBUF_LOCK;

/* FIXME: is this lower bound the right one? */<

你可能感兴趣的:(linux网卡缓冲区设置)