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!