1.TCP transmit and receive buffers default values
[Email protected]/]# Cat/proc/sys/net/ipv4/tcp_rmem
4096 87380 4194304
87380:tcp the default value of the receive buffer
[Email protected]/]# Cat/proc/sys/net/ipv4/tcp_wmem
4096 16384 4194304
16384:tcp default value of the Send buffer
2.UDP transmit and receive buffers default values
[Email protected]/]# Cat/proc/sys/net/core/rmem_default
110592
110592:UDP the default value of the receive buffer
[Email protected]/]# Cat/proc/sys/net/core/wmem_default
110592
110592:UDP default value of the Send buffer
3 . TCP or UDP transmit/Receive buffer maximum value
[Email protected]/]# Cat/proc/sys/net/core/rmem_max
131071
The 131071:TCP or UDP receive buffer can be half the maximum set value.
That means call setsockopt (S, Sol_socket, So_rcvbuf, &rcv_size, &optlen); If the rcv_size is more than 131071, then
GetSockOpt (S, Sol_socket, So_rcvbuf, &rcv_size, &optlen); The resulting value is equal to 131071 * 2 = 262142
[Email protected]/]# Cat/proc/sys/net/core/wmem_max 131071
The 131071:TCP or UDP send buffer can be half the maximum set value.
With the same principle as above
4. TCP or UDP transmit/receive buffer minimum value
The minimum value for the TCP or UDP receive buffer is bytes, which is determined by the kernel macro;
The minimum value for the TCP or UDP send buffer is 2048 bytes, which is determined by the kernel's macro
Example:
int isock =-1;
Isock = socket (af_inet, SOCK_DGRAM, 0);
int irecvlen = 300*1024;
int irecvlen_2 = 0;
int ioptlen = 4;
int iRet =-1, iret_2 =-1;
IRet = setsockopt (Isock, Sol_socket, So_rcvbuf, &irecvlen, 4);
Iret_2 = getsockopt (Isock, Sol_socket, So_rcvbuf, &irecvlen_2, &ioptlen);
printf ("Recvlen 2 is%d[%d:%d].\n", Irecvlen_2, IRet, iret_2);
If the default UDP buffer has a maximum value of 110592 Bytes, when you want to set it to 300KB through the setsockopt () function, it exceeds the maximum limit of twice times, so use the getsockopt () The function gets the actual set buffer length of 221184Bytes (110592*2).
TCP and UDP buffer size summary (reprint)