TCP and UDP buffer size summary (reprint)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.