| 44 | } |
| 45 | |
| 46 | static void do_complete(void* owner, operation* base, |
| 47 | const boost::system::error_code& /*ec*/, |
| 48 | std::size_t /*bytes_transferred*/) |
| 49 | { |
| 50 | // Take ownership of the handler object. |
| 51 | wait_handler* h(static_cast<wait_handler*>(base)); |
| 52 | ptr p = { boost::asio::detail::addressof(h->handler_), h, h }; |
| 53 | |
| 54 | BOOST_ASIO_HANDLER_COMPLETION((*h)); |
| 55 | |
| 56 | // Take ownership of the operation's outstanding work. |
| 57 | handler_work<Handler, IoExecutor> w( |
| 58 | static_cast<handler_work<Handler, IoExecutor>&&>( |
| 59 | h->work_)); |
| 60 | |
| 61 | // Make a copy of the handler so that the memory can be deallocated before |
| 62 | // the upcall is made. Even if we're not about to make an upcall, a |
| 63 | // sub-object of the handler may be the true owner of the memory associated |
| 64 | // with the handler. Consequently, a local copy of the handler is required |
| 65 | // to ensure that any owning sub-object remains valid until after we have |
| 66 | // deallocated the memory here. |
| 67 | detail::binder1<Handler, boost::system::error_code> |
| 68 | handler(h->handler_, h->ec_); |
| 69 | p.h = boost::asio::detail::addressof(handler.handler_); |
| 70 | p.reset(); |
| 71 | |
| 72 | // Make the upcall if required. |
| 73 | if (owner) |
| 74 | { |
| 75 | fenced_block b(fenced_block::half); |
| 76 | BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); |
| 77 | w.complete(handler, handler.handler_); |
| 78 | BOOST_ASIO_HANDLER_INVOCATION_END; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | Handler handler_; |