I'm looking for a design suggestion here. If we are using socket.async_write, the client code which is sending the message won't have a synchronous result to know if it succeeded or failed, and therefore doesn't know if it should retry sending (or whatever error handling would be invoked when a message failed to send.)
The boost docs say:
This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:
- All of the data in the supplied buffers has been written. That is, the bytes transferred is equal to the sum of the buffer sizes.
- An error occurred.
The callback method will tell you both where there was an error, and also number of bytes actually written (which if less than buffer size, indicates an error).
So it seems like you need to keep a copy of any message until you get notified it was sent, either to try a resend or to notify calling code that the message didn't get sent.
Is there any way to pass to the async handler method a reference to the buffer/message which was being sent? Or would a better approach to maintain some container of messages being written, and then pop it out when the async write completes?