I was reading the documentation of Boost Asio and it says that
boost::asio::async_write_somemay NOT transfer all of the data to the peer. Consider using theasync_writefunction if you need to ensure that all data is written before the asynchronous operation completes.
So here is my question, in which cases should we use them, isn`t VERY important to ensure that all the data is written?! when to use async_write_some just this function seems to me useless?
async_write is useful in request-reply mode when you need to send a specific response that fully fits in your buffer. I.e. when you switch to reading mode after the message is sent.
But if you need to send more data than you have in your write buffer then it doesn't matter if the whole buffer is sent or not, because you still have more data to send. In that case ensuring that the whole buffer is sent is going to be inefficient because the last chunk may be smaller than it could have been if you just called async_write_some in a loop, filling up the buffer with more data as you go. For optimal performance you want to ensure there is always enough data in the send buffer to fill a full frame.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With