简体   繁体   English

boost async_write()和non_blocking socket.send()之间的区别

[英]Difference between boost async_write() and non_blocking socket.send()

'Cause we can set a socket to non blocking state by its member function non_blocking(true) . 因为我们可以通过其成员函数non_blocking(true)将套接字设置为非阻塞状态。

Is there any difference between async_write(socket, buffer) and non_blocking socket.send(buffer) ? async_write(socket, buffer)和non_blocking socket.send(buffer)有什么区别吗?

Will multiple socket.send(buffer) result in out-of-order data delivery, as the same the async_write(socket, buffer) does? async_write(socket, buffer)一样async_write(socket, buffer)多个socket.send(buffer)导致乱序的数据传递吗?

send does not guarantee you that all data was written to socket. send不能保证您所有数据都已写入套接字。 You should check out "bytes written" return value, error codes etc. In other hand, async_write will try to send until all data is sent or error occur. 您应该检查“已写入字节”的返回值,错误代码等。另一方面, async_write将尝试发送,直到所有数据发送完毕或发生错误为止。

Remarks from ip::tcp::send manual: ip :: tcp :: send手册中的注释:

The send operation may not transmit all of the data to the peer. 发送操作可能不会将所有数据都发送到对等方。 Consider using the write function if you need to ensure that all data is written before the blocking operation completes. 如果需要确保在阻塞操作完成之前已写入所有数据,请考虑使用写入功能。

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

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