I have a questions concerning boost::asio::ip::tcp::socket
and the associated write functions. From reading the Wikipedia article on the TCP, I understand, that TCP contains acknowledgement messages as well as checksums. Unfortunaly, I can't find any information on this in the boost::asio reference. As far as I understand boost::asio uses the OS implementation of the TCP, which should contain both features.
My question is what do the functions boost::asio::write
or boost::asio::async_write
guarantee when called with an boost::asio::ip::tcp::socket
. So what does it mean if the function returns/the callback function is called without error. I can imagine some possibilities:
If it is not 4. is there a way to enforce this using boost::asio (I mean within boost::asio, not implementing it yourself)?
It is #1, which is the way it should be. There are no guarantees that the data will ever be sent.
You think you want #4, but you really don't. The fact that the remote peer's network stack received the correct data is probably irrelevant to your application. You really want to know whether the data was received and processed correctly, which is beyond the scope of TCP, but easy enough to implement on top of TCP. (I recommend reading up on the OSI Model for an introduction to what TCP can be expected to do. Basically, you want to ensure that your data gets to the right application, or perhaps more, and TCP only ensures that it gets as far as the computer that the application is running on.)
To do what you want, send an in-band acknowledgement over the TCP link. You can also put the SHA-2 or some other hash of the data in the acknowledgement. You can also wait to send the acknowledgement until the data has been processed — e.g., wait until it has been written to disk and fsync()
has been called.
Locally detected errors will be reported. Connection error will also be reported. If you are using TCP, tcp-ack failure will be reported, but maybe at a later read or write call (when the os is notified of the tcp-hack failure).
So you can't be sure that when you issue a write that it is actually received. no write error means that the os knows currently no errors on the tcp connection you are using and that he buffered your data internally to transmit it to the tcp peer.
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