Set the socket buffer size

Source: Internet
Author: User

When the socket sends data, it first sends the data to the socket buffer, and then receives the function to retrieve the data from the buffer. If the sending end is particularly fast, the buffer will soon be filled up (the default socket is 1024 × 8 = 8192 bytes). At this time, we should set the buffer size according to the situation, which can be achieved through the setsockopt function.

 

Int Setsockopt (
Socket S,
Int Level,
Int Optname,
Const char * Optval,
Int Optlen
);

Eg:

Int optval = 1024*1024;
Int optlen = sizeof (INT );

 

Setsockopt (socket, sol_socket, so_rcvbuf, (char *) & optval, optlen );

 

Socket: socket for data transmission

Sol_socket: basic set of interfaces
So_rcvbuf: buffer for receiving data

Optval: buffer size

Optlen: the length of the variable pointing to the buffer size

 

 

There are a lot of details about this function on the Internet. Not used for the moment. Add more later!

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.