gpt4 book ai didi

c# - 什么条件导致 NetworkStream.Write 阻塞?

转载 作者:太空狗 更新时间:2023-10-29 19:26:35 24 4
gpt4 key购买 nike

NetworkStream.Write 是仅在将要发送的数据放入 TCP 发送缓冲区之前阻塞,还是在接收主机实际确认数据之前阻塞?

注意:套接字配置为阻塞 I/O。

编辑 糟糕,当然没有TcpClient.Write 这样的东西!我们都知道我们在谈论 TcpClient.GetStream().Write,它实际上是 NetworkStream.Write!

最佳答案

除非 .net 使用的不是 winsock,否则根据 winsock 引用:

The successful completion of a send function does not indicate that the data was successfully delivered and received to the recipient. This function only indicates the data was successfully sent.

If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode. On nonblocking stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both the client and server computers.

假设 write 正在调用下面的 send,那么对 winsock 文档的严格解释将表明不能保证数据在返回时到达管道的另一端。

这是我引用的 winsock 文档的链接: http://msdn.microsoft.com/en-us/library/windows/desktop/ms741416(v=VS.85).aspx

关于c# - 什么条件导致 NetworkStream.Write 阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7667254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com