Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>io_service</code> is never returning because there is always work in the <code>io_service</code>. When <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/basic_socket_acceptor/close/overload1.html" rel="nofollow"><code>acceptor::close()</code></a> is invoked, the <code>acceptor</code>'s asynchronous accept operations will be cancelled immediately. The handlers for these cancelled operations will be passed the <code>boost::asio::error::operation_aborted</code> error.</p> <p>In the current code, the problem is the result of a new asynchronous accept operation always being initiated, even if the <code>acceptor</code> has been closed. Thus, work is always being added to the <code>io_service</code>.</p> <pre><code>void start_accept(){ // If the acceptor is closed, handle_accept will be ready to run with an // error. acceptor_.async_accept(..., handle_accept); } void handle_accept(const system::error_code&amp; error){ if(!error) { connection-&gt;start(); } // Always starts a new async accept operation, even if the acceptor // has closed. start_accept(); } void handle_stop(){ acceptor_.close(); } </code></pre> <p>The Boost.Asio examples prevents this from occurring checking if <code>acceptor_</code> has been closed in the <code>handle_accept</code> call. If the <code>acceptor_</code> is no longer open, then the handler returns early without adding more work to the <code>io_service</code>.</p> <p>Here is the relevant snippet from from the <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/example/http/server/server.cpp" rel="nofollow">HTTP Server 1</a> example:</p> <pre><code>void server::handle_accept(const boost::system::error_code&amp; e) { // Check whether the server was stopped by a signal before this completion // handler had a chance to run. if (!acceptor_.is_open()) { return; } if (!e) { connection_manager_.start(new_connection_); } start_accept(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload