s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
SEND_BUF_SIZE = 167
RECV_BUF_SIZE = 191
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
print s.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
s.setsockopt( socket.SOL_SOCKET, socket.SO_SNDBUF, SEND_BUF_SIZE)
s.setsockopt( socket.SOL_SOCKET, socket.SO_RCVBUF, RECV_BUF_SIZE)
print s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
print s.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
node2:/root/test#python t7.py
87380
16384
2280
2048
实际最小是 分别
1588 #define SOCK_MIN_SNDBUF 2048
1589 /*
1590 * Since sk_rmem_alloc sums skb->truesize, even a small frame might need
1591 * sizeof(sk_buff) + MTU + padding, unless net driver perform copybreak
1592 */
1593 #define SOCK_MIN_RCVBUF (2048 + sizeof(struct sk_buff))
1594
if (val > sysctl_wmem_max)
val = sysctl_wmem_max;
set_sndbuf:
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
if ((val * 2) < SOCK_MIN_SNDBUF)
sk->sk_sndbuf = SOCK_MIN_SNDBUF;
else
sk->sk_sndbuf = val * 2;
接收buffer 是2280-2048 = 232 来自sk_buff
#include <linux/skbuff.h> /* struct sk_buff */