void server::handle_accept(session::pointer new_session, const boost::system::error_code& error) { if (!error) { // Check whether the server was stopped by a signal before this // completion handler had a chance to run. if (!acceptor_.is_open()) { return; } new_session->start(); new_session = make_session(); auto accept_callback = boost::bind(&server::handle_accept, this, new_session, boost::asio::placeholders::error); acceptor_.async_accept(new_session->get_socket(), accept_callback); } }