- 论坛徽章:
- 0
|
http://www.kernel.org/doc/man-pages/online/pages/man7/tcp.7.html
1: Buffer size
The maximum sizes for socket buffers declared via the SO_SNDBUF and SO_RCVBUF
mechanisms are limited by the values in the /proc/sys/net/core/rmem_max and
/proc/sys/net/core/wmem_max files. Note that TCP actually allocates twice the
size of the buffer requested in the setsockopt(2) call, and so a succeeding
getsockopt(2) call will not return the same size of buffer as requested in the
setsockopt(2) call. TCP uses the extra space for administrative purposes and
internal kernel structures, and the /proc file values reflect the larger sizes
compared to the actual TCP windows. On individual connections, the socket
buffer size must be set prior to the listen(2) or connect(2) calls in order to
have it take effect. See socket(7) for more information.
由上文可看出,socket缓存大小不仅取决于setsockopt设置的大小,还受限于/proc/sys/net/core/rmem_max and /proc/sys/net/core/wmem_max
2: UDP由于BUFFER SIZE引起的丢包问题
参见《UNIX® Network Programming Volume 1》 中 8.13 Lack of Flow Control with UDP
注意如下描述:
Why do we set the receive socket buffer size to 220 x 1,024 in Figure 8.22? The maximum size of a socket receive buffer in FreeBSD 5.1 defaults to 262,144 bytes (256 x 1,024), but due to the buffer allocation policy (described in Chapter 2 of TCPv2), the actual limit is 233,016 bytes. Many earlier systems based on 4.3BSD restricted the size of a socket buffer to around 52,000 bytes
所以可以解答Linux 系统是32K 发送数据也是32K,为什么在27K时可以接收成功,看样子是由于BUFFER里面除了数据还包括一些头结构,导致真正可用数据不到32K. |
|