Reputation: 12371
I've known that each socket has a buffer to read or write data. For example, on a Linux server, we can check the buffer size with the command cat /proc/sys/net/ipv4/tcp_rmem
and cat /proc/sys/net/ipv4/tcp_wmem
.
As my understanding, some algorithms of TCP protocol, such as the sliding window, need to use the buffer of a socket.
If I'm right, I want to know what will happen if the size of the socket-buffer is not enough, for example, what if a huge data packet is coming. Is there any other buffer(OS level or network interface card/hardware level) that can be used? If not, does it mean that some data has to be abandoned?
Upvotes: 1
Views: 1821
Reputation: 1057
TCP sockets use buffering in the protocol stack. The stack itself implements flow control so that if the server's buffer is full, it will stop the client stack from sending more data. Your code will see this as a blocked call to send(). The buffer size can vary widely from a few kB to several MB.
Upvotes: 0
Reputation: 123270
If there is not enough space in the buffer data will be discarded. In the case of TCP this will result in the peer sending the data again since they were not ack'ed. In case of UDP the data are simply lost. TCP will also advertise its receive window so that the peer will hopefully not send the data faster than they can be processed (i.e. taken out of the buffer).
Upvotes: 4