Boost :: asio async handlers called without errors after cancellation

My code uses boost :: asio and io_service in the same thread to perform various socket operations. All operations are asynchronous, and each handler depends on boost::system::error_code(especially boost::asio::error::operation_aborted) to determine the result of the operation.

It worked fine until I changed the logic to make several parallel connections and choose the fastest. That is, when the first handler fires async_read_some, I cancel the other sockets (shutdown, close-all) and continue the current one. In 95% of cases, other socket read handlers are called with an operation_aborted error. However, sometimes these read handlers call without error, telling me that they successfully received N bytes.

But the documentation for socket :: cancel () indicates :

This function calls all outstanding asynchronous connections, sending and immediately executing operations, and handlers for canceled operations will fail boost::asio::error::operation_aborted.

So the questions are: can I really rely on the error operation_abortedin the production code? If I can, is this a bug in Asio from boost 1.46.1? If I can’t, is there official documentation on this?

+5
source share
2 answers

Ok answers:

  • No, I can’t only rely on a mistake operation_aborted.
  • Of course, this is not a mistake in Asio, just a lack of experience on my side.
  • . , , :

, cancel(), :

  • ;
  • .

, , io_service, , - .

, , , , , Asio, . Asio , , .

, , , , socket cancel, . , , .

+11

. , , - ( ). .

, .

+2

All Articles