TCP sockets: where does the incoming data go after ack (leaves the tcp read buffer), but before read () / recv ()?

If I have a TCP connection that transfers data at a speed of 200 KB / s, but only I read() / recv() from the socket once a second, where are those 200 KB of data stored at that time?

As far as I know, the data leaves the TCP socket read buffer after the ack is sent to the sender, and it is too small anyway to store 200 Kbytes of data, where it will wait until it read() / recv() my client?

Thanks!!

The following response request data leaves the TCP read buffer as soon as it is ACK'ed before reading () / recv () d:

stack overflow

"The size of the receiver socket receive buffer determines how much data can be in flight without confirmation"

Maybe my assumption is wrong and the data gets ACK'd only after the program readpace () / recv () d)?

+4
source share
3 answers

data leaves the TCP socket read buffer after ack is sent to the sender

No. It leaves a receive buffer when you read it through recv(), recvfrom(), read(), etc.

The following response request data leaves the TCP read buffer as soon as it is ACK'ed

Fiddlesticks. I wrote this, and he positively and absolutely does not “require” such a thing.

You are thinking of a send buffer. Data is deleted from the sender's send buffer when it is connected by the receiver. This is because the sender now knows that he has arrived and does not need him for any retries.

Maybe my assumption is wrong and the data gets ACK'd only after the program readpace () / recv () d)?

Yes, your assumption is wrong, and it is also an alternative spec. Data gets ACK'd upon arrival and is deleted using read()/recv().

+7
source

When the data is correctly received, it enters the TCP read buffer and is immediately subject to confirmation. This does not mean that the confirmation is sent immediately, as it will be more efficient to combine the confirmation with updating the window size or with transferring data over the connection in the other direction or with confirmation of more data.

For example, suppose you send one byte at a time corresponding to the user, and the other side has a receive buffer of 50,000 bytes. It tells you that the window size is 50,000 bytes, which means that you can send as many bytes of data without receiving anything further. Each byte of data sent closes the window by one byte. Now the receiver can send a packet confirming one byte as soon as it was correctly received and has entered a TCP receive buffer with a window size of 49999 bytes, because this is how much space is left in the receive buffer. Confirmation will allow you to remove the byte from your send buffer, since now you know that the byte is received correctly and will not need to be repeated. Then, when the application reads it from the TCP receive buffer using read() or recv() , which will make a buffer space for one additional byte of data to be received, so it can then send another packet updating the TCP window size with one byte, so that you can send again 50,000 bytes, and not 49999. Then the application can echo a character or send another answer to the data, as a result of which a third packet will be sent. Fortunately, a well-designed TCP implementation will not do this, as it will create a lot of overhead. It will ideally send one packet containing any data going in the other direction, as well as any confirmation confirmation and window size as part of the same packet. It might seem that confirmation is sent when the application reads the data and leaves the receive buffer, but it may just be the event that caused the packet to be sent. However, it does not always delay confirmation and does not delay it indefinitely; after a short timeout without any other activity, he will send any delayed confirmation.

Regarding the size of the receive buffer, which contains received data that has not yet been read by the application, which can be controlled using setsockopt() with the SO_RCVBUF option. The default value may vary depending on the OS, memory size and other parameters. For example, fast connections with high latency (such as satellite) may require large buffers, although this will increase memory usage. There is also a send buffer ( SO_SNDBUF ), which includes data that has not yet been transmitted or has been transmitted but not yet acknowledged.

+2
source

Your OS will buffer a certain amount of incoming TCP data. For example, on Solaris, this default value is 56 KB, but can be reasonably configured for a few MB if large bursts are expected. By default, Linux has much smaller defaults, but you can see the instructions on this webpage to increase these defaults: http://www.cyberciti.biz/faq/linux-tcp-tuning/

+1
source

Source: https://habr.com/ru/post/1480490/


All Articles