My code uses boost::asio and io_service in a single thread to perform various socket operations. All operations are asynchronous and every handler depends on the boost::system::error_code
(particularly boost::asio::error::operation_aborted
) to determine the result of the operation.
It's been working perfectly well until I changed the logic to make several concurrent connections and pick the fastest one. That is, when the first async_read_some
handler fires, I cancel other sockets (shutdown, close - everything) and proceed with the current one. In 95% of cases other sockets' read handlers are invoked with the operation_aborted error. However sometimes, these read handlers are invoked without errors, telling me that they have successfully received N bytes.
But the documentation for socket::cancel() states:
This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the
boost::asio::error::operation_aborted
error.
So, the questions: Can I really rely on the operation_aborted
error in production code? If I can, is it a bug in Asio from boost 1.46.1? If I can't, is there any official documentation regarding this?
operation_aborted
to be passed to any handlers that have not already executed (and are waiting to be called). – Chad