What socket send/recv operations can run concurrently using Boost.Asio

假如想象 提交于 2019-12-10 23:28:43

问题


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:

  1. calling two async_send operations concurrently on an UDP socket.
  2. calling two async_receive operations concurrently on an UDP socket.
  3. calling two async_send operations concurrently on a TCP socket.
  4. calling two async_receive operations concurrently on a TCP socket.

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.


回答1:


The same thing happens as would happen without Boost ASIO:

calling two async_send operations concurrently on an UDP socket.

Both datagrams will be sent.

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.

calling two async_send operations concurrently on a TCP socket.

The data may interleave unpredictably.

calling two async_receive operations concurrently on a TCP socket.

The data may interleave unpredictably.



来源:https://stackoverflow.com/questions/24998899/what-socket-send-recv-operations-can-run-concurrently-using-boost-asio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!