众所周知,它getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &opt_val, &opt_len);返回之前分配的 tcp 缓冲区大小的两倍setsockopt()。
(如写在man 7 tcp:
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,)
所以如果我这样做setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (int *)&buf_size, sizeof(buf_size))了buf_size = 256K,512K就会被分配并返回getsockopt()。
我想计算tcp buffer. 为此,我正在计算队列 ( sk->sk_write_queue->len) 中每个数据包的长度,而skis struct sock *sk。
碰巧有时返回的长度大于256K. (例如,我得到294879的字节32735数大于256K)。
为什么会发生?它包括"extra space for administrative purposes and internal kernel structures"作为getsockopt(.., SOL_SOCKET, SO_SNDBUF, ..)?
谢谢。