好的,答案是:
>不,我不能仅仅依赖于operation_aborted错误.
>当然,这不是Asio的一个错误,只是缺乏经验.
>有一些官方documentation.它是定时器,而不是插座,但同样的原则适用:
如果在调用cancel()时计时器已经过期,则异步等待操作的处理程序将:
>已被调用;要么
>已经在不久的将来排队等待调用.
基本上,我错误地假设如果我为io_service使用单个线程,那么在执行某些处理程序时将阻止每个操作.
我报告的行为实际上很有意义,似乎每个使用Asio的人都知道这一点.我已经梳理了Asio的邮件列表,并在here,here,here和here这个主题上找到了很多讨论.
For instance, a write operation may complete successfully while you are inside a handler but before you have got around to calling socket cancel, causing its completion handler to be posted to the queue. As I understand it, the error code is determined by the status of the operation that completed, not the state of the socket at the time the handler is picked off the queue and executed.