socket从内核角度讲一次最大允许读取多少字节

socket从内核角度讲一次最大允许读取多少字节

2012-12-07 00:22

1、从socket里一次最大读取字节数取决于接收buffer的大小,亦即socket的SO_RCVBUF对应的数值的2倍,这个2倍关系是内核决定的。
2、所以关键在于SO_RCVBUF的大小了。SO_RCVBUF大小,每个系统可能不一样,比如我使用linux,rmem_max存储了它的最大值:
[root@localhost sockopt]# cat /proc/sys/net/core/rmem_max
124928
3、所以对于我这台电脑,最大接收buffer是124928*2的大小,也就是说最大允许一次读取124928*2大小了。
======================================================================
以下是linux对该buffer的描述
 SO_RCVBUF
              Sets or gets the maximum socket receive buffer in bytes.  The  kernel  doubles
              this value (to allow space for bookkeeping overhead) when it is set using set-
              sockopt(2), and this doubled value is returned by getsockopt(2).  The  default
              value  is  set  by  the  /proc/sys/net/core/rmem_default file, and the maximum
              allowed value is set by the  /proc/sys/net/core/rmem_max  file.   The  minimum
              (doubled) value for this option is 256.
================================================

你可能感兴趣的:(socket从内核角度讲一次最大允许读取多少字节)