问题
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:
- calling two async_send operations concurrently on an UDP socket.
- calling two async_receive operations concurrently on an UDP socket.
- calling two async_send operations concurrently on a TCP socket.
- 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