简体   繁体   English

Boost Asio同步写不会阻塞

[英]Boost asio synchronous write doesn't block

I've wrote an application that sends information through a socket using a TCP connection. 我编写了一个使用TCP连接通过套接字发送信息的应用程序。 For several reasons, I'm using blocking calls but I've noticed that boost::asio::write() method doesn't block when the other machine (the one receiving the data) disconnects. 出于多种原因,我使用了阻塞调用,但是我注意到当另一台计算机(接收数据的那台计算机)断开连接时, boost::asio::write()方法不会阻塞。 It doesn't raise an error either. 它也不会引发错误。

Is this the expected behavior? 这是预期的行为吗?

Socket write will block when there is no room in the buffer, otherwise it will return as soon as data is in the buffer to send, not until data is delivered to the recipient. 当缓冲区中没有空间时,套接字写操作将阻塞,否则,它将在缓冲区中的数据发送后立即返回,直到将数据传递给接收方。 Also network stack may not detect that another side disconnected immediately, so you may or may not see error code on write. 另外,网络堆栈可能无法检测到另一侧立即断开连接,因此您可能会或可能不会在写入时看到错误代码。 So yes, it is expected behavior. 是的,这是预期的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM