| 130 | } |
| 131 | |
| 132 | void Stop() |
| 133 | { |
| 134 | auto stop_promise = std::make_shared<std::promise<void>>(); |
| 135 | auto stop_future = stop_promise->get_future(); |
| 136 | |
| 137 | // Posting the close to the acceptors strand ensures |
| 138 | // we do not have a race condition with async_accept. |
| 139 | boost::asio::post(acceptor.get_executor(), |
| 140 | [self = shared_from_this(), stop_promise]() |
| 141 | { |
| 142 | boost::beast::error_code ec; |
| 143 | (void)self->acceptor.close(ec); |
| 144 | if (ec) |
| 145 | { |
| 146 | util::Log(logDEBUG) << "Error closing acceptor: " << ec.message(); |
| 147 | } |
| 148 | // Stop the io_context |
| 149 | self->io_context.stop(); |
| 150 | stop_promise->set_value(); |
| 151 | }); |
| 152 | |
| 153 | // The above function is async, this simply waits until it succeeded |
| 154 | stop_future.wait(); |
| 155 | } |
| 156 | |
| 157 | void RegisterServiceHandler(std::unique_ptr<ServiceHandlerInterface> service_handler_) |
| 158 | { |