对于 TCP,从 "write()" 返回是否意味着对等应用程序具有 "read()" 数据?
For TCP, does returning from "write()" mean that the peer app has "read()" the data?
我正在编写一个 C/S 程序,客户端和服务器都可以在任意时间向对等方发送数据(无需明确确认)。我想知道如果客户端和服务器巧合地同时写入对等点,是否可能会死锁。
那么从 write()
返回是否意味着对等应用程序已经 read()
数据?或者它仅意味着对等方的内核已获取数据并将在下一个 read()
?
交付给应用程序
(EJP 的回答修正了我对 write()/send()/...
的完全错误理解。为了添加一些权威信息,我在 POSIX 标准中找到了关于 send
:
Successful completion of a call to send() does not guarantee delivery of the message. A return value of -1 indicates only locally-detected errors.
Linux关于send()
的手册页不是很清楚:
No indication of failure to deliver is implicit in a send(). Locally detected errors are indicated by a return value of -1.
或者是因为我作为非英语母语的人无法完全理解第一句话。 )
没有。如果你认为它是一个数据管道,returning from write
意味着你的数据已经进入管道,没有它已经从另一端离开管道。
事实上,由于管道是数据可能采用数百种不同路径中的任何一种的管道,您甚至不能保证它会到达另一端:- ) 如果发生这种情况,您将在稍后的某个日期收到通知,可能是 后续 write
失败。
可能被屏蔽了:
- 由于电缆损坏,正在尝试退出您的机器,
- 在某个路径的瓶颈处,
- 通过目的地的网络堆栈,
- 通过网络路径中某些设备的网络堆栈,比简单的集线器更智能,
- 因为另一端的应用程序被占用,
- 等等。
来自 write
的成功 return 意味着您的 local 网络堆栈已接受您的数据并将在适当的时候处理它。
I'm wondering if it could possibly deadlock if the client and server coincidentally write to the peer at the same time.
它不能,除非一个或两个对等点读取速度非常慢并且已关闭其接收 window。 TCP 是全双工的。
So does returning from write() mean that the peer application has already read() the data?
没有
Or it only means the peer's kernel has got the data and would deliver to the app on next read()?
没有
表示数据已经到达你的内核,正在排队等待传输。
the returning from write() means the TCP ACK has already been received.
不,不是。
u mean returning from write() only means the data has reached the sender's kernel?
这不仅是我的意思,也是我所说的。
I'd think the sender's already received the TCP ACK so reached the peer's kernel.
没有
我正在编写一个 C/S 程序,客户端和服务器都可以在任意时间向对等方发送数据(无需明确确认)。我想知道如果客户端和服务器巧合地同时写入对等点,是否可能会死锁。
那么从 write()
返回是否意味着对等应用程序已经 read()
数据?或者它仅意味着对等方的内核已获取数据并将在下一个 read()
?
(EJP 的回答修正了我对 write()/send()/...
的完全错误理解。为了添加一些权威信息,我在 POSIX 标准中找到了关于 send
:
Successful completion of a call to send() does not guarantee delivery of the message. A return value of -1 indicates only locally-detected errors.
Linux关于send()
的手册页不是很清楚:
No indication of failure to deliver is implicit in a send(). Locally detected errors are indicated by a return value of -1.
或者是因为我作为非英语母语的人无法完全理解第一句话。 )
没有。如果你认为它是一个数据管道,returning from write
意味着你的数据已经进入管道,没有它已经从另一端离开管道。
事实上,由于管道是数据可能采用数百种不同路径中的任何一种的管道,您甚至不能保证它会到达另一端:- ) 如果发生这种情况,您将在稍后的某个日期收到通知,可能是 后续 write
失败。
可能被屏蔽了:
- 由于电缆损坏,正在尝试退出您的机器,
- 在某个路径的瓶颈处,
- 通过目的地的网络堆栈,
- 通过网络路径中某些设备的网络堆栈,比简单的集线器更智能,
- 因为另一端的应用程序被占用,
- 等等。
来自 write
的成功 return 意味着您的 local 网络堆栈已接受您的数据并将在适当的时候处理它。
I'm wondering if it could possibly deadlock if the client and server coincidentally write to the peer at the same time.
它不能,除非一个或两个对等点读取速度非常慢并且已关闭其接收 window。 TCP 是全双工的。
So does returning from write() mean that the peer application has already read() the data?
没有
Or it only means the peer's kernel has got the data and would deliver to the app on next read()?
没有
表示数据已经到达你的内核,正在排队等待传输。
the returning from write() means the TCP ACK has already been received.
不,不是。
u mean returning from write() only means the data has reached the sender's kernel?
这不仅是我的意思,也是我所说的。
I'd think the sender's already received the TCP ACK so reached the peer's kernel.
没有