What socket send/recv operations can run concurren

2019-07-15 00:59发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-15 01:46

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.

查看更多
登录 后发表回答