使用 Boost.Asio 可以同时运行哪些套接字发送/接收操作 [英] What socket send/recv operations can run concurrently using Boost.Asio
问题描述
我知道可以在 TCP 和 UDP 套接字上同时运行 async_send 和 async_receive 操作.但是在这些情况下的预期行为是什么:
I am aware that one can run async_send and async_receive operations concurrently on TCP and UDP sockets. But what is the expected behavior in these situations:
- 在 UDP 套接字上同时调用两个 async_send 操作.
- 在 UDP 套接字上同时调用两个 async_receive 操作.
- 在 TCP 套接字上同时调用两个 async_send 操作.
- 在 TCP 套接字上同时调用两个 async_receive 操作.
我主要对第一种情况感兴趣;由于 UDP 不一定保留发送数据包的顺序,因此我不太关心它们的发送顺序是否与调用 async_send 的顺序不同.
I'm mainly interested in the first case; since UDP doesn't necessarily preserve the order of sent packets, I don't care much if they are sent in order different from the one async_send was invoked.
推荐答案
与没有 Boost ASIO 时发生的情况相同:
The same thing happens as would happen without Boost ASIO:
在一个 UDP 套接字上同时调用两个 async_send 操作.
calling two async_send operations concurrently on an UDP socket.
两个数据报都会被发送.
Both datagrams will be sent.
在 UDP 套接字上同时调用两个 async_receive 操作.
calling two async_receive operations concurrently on an UDP socket.
哪个操作接收下一个数据报是任意的,但两个操作都会正常运行.
It is arbitrary which operation will receive the next datagram, but both operations will behave normally.
在 TCP 套接字上同时调用两个 async_send 操作.
calling two async_send operations concurrently on a TCP socket.
数据可能会不可预测地交错.
The data may interleave unpredictably.
在 TCP 套接字上同时调用两个 async_receive 操作.
calling two async_receive operations concurrently on a TCP socket.
数据可能会不可预测地交错.
The data may interleave unpredictably.
这篇关于使用 Boost.Asio 可以同时运行哪些套接字发送/接收操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!