Linux TCP/IP非阻塞发送给套接字流。TCP recv缓冲区发生了什么变化?

时间:2022-06-06 18:20:16

This pertains to Linux kernel 2.6 TCP sockets.

这属于Linux内核2.6 TCP套接字。

I am sending a large amount of data, say 300 MB, with a non-blocking send to another client who receives 8 MB at a time.

我正在发送大量数据,比如300 MB,并向另一个每次接收8 MB的客户端发送非阻塞数据。

After one 8 MB receive, the "receiver" stops receiving because it wants to perform other tasks, such as error handling. The sender would get a EWOULDBLOCK, but since it's asynchronous communication, the send would try and fill up the TCP recv buffer on the other end.

在一个8mb的接收之后,“接收者”停止接收,因为它想执行其他任务,比如错误处理。发送方将获得一个edbif锁,但是由于是异步通信,发送方将尝试填充另一端的TCP recv缓冲区。

My question is: would there still be data in the TCP recv buffer even though the "sender" got a EWOULDBLOCK and the "receiver" stops receiving? The same socket is used for error handling, so would the "receiver" have to then clear the TCP recv buffer before trying to reuse the existing socket?

我的问题是:即使“发送方”得到eif锁,“接收方”停止接收,TCP recv缓冲区中是否仍然有数据?相同的套接字用于错误处理,那么“接收方”在尝试重用现有套接字之前,是否必须清除TCP recv缓冲区?

2 个解决方案

#1


4  

Yes. It is quite possible (and in fact likely) that when you get EWOULDBLOCK, some data you have already sent has not yet been read by the recieving application. This buffered data will be available to the next read on the socket.

是的。很有可能(实际上很可能)当您得到ewill dblock时,您已经发送的一些数据还没有被接收应用程序读取。此缓冲数据将可用于套接字上的下一次读取。

This means that if your reciever then sends a "Ooops, don't send any more" message back to the sender, the sender can't act on that message and "un-send" the data. Once it's been passed to write()/send(), it's on its way and can't be recalled.

这意味着,如果您的收件人随后发送“Ooops,不要再发送”消息给发送方,发送方不能对该消息采取行动并“取消发送”数据。一旦它被传递给write()/send(),它就在路上了,不能被重新调用。

Your receiver will have to handle this eventuality by reading out the data it's no longer interested in and discarding it, which will mean you'll need some kind of transaction delimiters in your data stream.

您的接收方必须通过读取它不再感兴趣的数据并丢弃它来处理这种情况,这意味着您需要在数据流中使用某种事务分隔符。

#2


0  

My question is: would there still be data in the TCP recv buffer even though the "sender" got a EWOULDBLOCK and the "receiver" stops receiving?

我的问题是:即使“发送方”得到eif锁,“接收方”停止接收,TCP recv缓冲区中是否仍然有数据?

There is data in the TCP receive buffer because the sender got EWOULDBLOCK. That's the only condition it can happen under.

在TCP接收缓冲区中有数据,因为发送者得到了edblock。这是唯一的条件。

Your question doesn't make sense.

你的问题没有道理。

#1


4  

Yes. It is quite possible (and in fact likely) that when you get EWOULDBLOCK, some data you have already sent has not yet been read by the recieving application. This buffered data will be available to the next read on the socket.

是的。很有可能(实际上很可能)当您得到ewill dblock时,您已经发送的一些数据还没有被接收应用程序读取。此缓冲数据将可用于套接字上的下一次读取。

This means that if your reciever then sends a "Ooops, don't send any more" message back to the sender, the sender can't act on that message and "un-send" the data. Once it's been passed to write()/send(), it's on its way and can't be recalled.

这意味着,如果您的收件人随后发送“Ooops,不要再发送”消息给发送方,发送方不能对该消息采取行动并“取消发送”数据。一旦它被传递给write()/send(),它就在路上了,不能被重新调用。

Your receiver will have to handle this eventuality by reading out the data it's no longer interested in and discarding it, which will mean you'll need some kind of transaction delimiters in your data stream.

您的接收方必须通过读取它不再感兴趣的数据并丢弃它来处理这种情况,这意味着您需要在数据流中使用某种事务分隔符。

#2


0  

My question is: would there still be data in the TCP recv buffer even though the "sender" got a EWOULDBLOCK and the "receiver" stops receiving?

我的问题是:即使“发送方”得到eif锁,“接收方”停止接收,TCP recv缓冲区中是否仍然有数据?

There is data in the TCP receive buffer because the sender got EWOULDBLOCK. That's the only condition it can happen under.

在TCP接收缓冲区中有数据,因为发送者得到了edblock。这是唯一的条件。

Your question doesn't make sense.

你的问题没有道理。