Exemplo n.º 1
0
void start_accept( ba::ip::tcp::acceptor &accept )
{
    stream_sptr new_point(my_async_reader::create(accept.get_io_service( )));
    accept.async_accept(
                new_point->get_stream( ),
                boost::bind( accept_handle, ba::placeholders::error,
                             new_point, boost::ref( accept ) ) );
}
Exemplo n.º 2
0
  void start_listening() {
    using boost::asio::ip::tcp;
    system::error_code error;
    service_.reset();  // this allows repeated cycles of run -> stop ->
                       // run
    tcp::resolver resolver(service_);
    tcp::resolver::query query(address_, port_);
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error);
    if (error) {
      BOOST_NETWORK_MESSAGE("Error resolving '" << address_ << ':' << port_);
      return;
    }
    tcp::endpoint endpoint = *endpoint_iterator;
    acceptor.open(endpoint.protocol(), error);
    if (error) {
      BOOST_NETWORK_MESSAGE("Error opening socket: " << address_ << ":"
                                                     << port_);
      return;
    }
    socket_options_base::acceptor_options(acceptor);
    acceptor.bind(endpoint, error);
    if (error) {
      BOOST_NETWORK_MESSAGE("Error binding socket: " << address_ << ":"
                                                     << port_);
      return;
    }
    acceptor.listen(asio::socket_base::max_connections, error);
    if (error) {
      BOOST_NETWORK_MESSAGE("Error listening on socket: '"
                            << error << "' on " << address_ << ":" << port_);
      return;
    }
    new_connection.reset(new connection(service_, handler, *thread_pool, ctx_));
    acceptor.async_accept(
#ifdef BOOST_NETWORK_ENABLE_HTTPS
        new_connection->socket().next_layer(),
#else
        new_connection->socket(),
#endif
        boost::bind(&async_server_base<Tag, Handler>::handle_accept, this,
                    boost::asio::placeholders::error));
    listening = true;
    scoped_mutex_lock stopping_lock(stopping_mutex_);
    stopping = false;  // if we were in the process of stopping, we revoke
                       // that command and continue listening
    BOOST_NETWORK_MESSAGE("Now listening on socket: '" << address_ << ":"
                                                       << port_ << "'");
  }
Exemplo n.º 3
0
  void handle_accept(boost::system::error_code const &ec) {
    {
      scoped_mutex_lock stopping_lock(stopping_mutex_);
      if (stopping)
        return;  // we dont want to add another handler instance, and we
                 // dont want to know about errors for a socket we dont
                 // need anymore
    }

    if (ec) {
      BOOST_NETWORK_MESSAGE("Error accepting connection, reason: " << ec);
    }

#ifdef BOOST_NETWORK_ENABLE_HTTPS
    socket_options_base::socket_options(new_connection->socket().next_layer());
#else
    socket_options_base::socket_options(new_connection->socket());
#endif

    new_connection->start();
    new_connection.reset(new connection(service_, handler, *thread_pool, ctx_));
    acceptor.async_accept(
#ifdef BOOST_NETWORK_ENABLE_HTTPS
        new_connection->socket().next_layer(),
#else
        new_connection->socket(),
#endif
        boost::bind(&async_server_base<Tag, Handler>::handle_accept, this,
                    boost::asio::placeholders::error));
  }
Exemplo n.º 4
0
 void acceptor_options(asio::ip::tcp::acceptor& acceptor) {
   acceptor.set_option(acceptor_reuse_address);
   acceptor.set_option(acceptor_report_aborted);
 }
 void async_accept(asio::ip::tcp::acceptor& tcp_acceptor, AcceptHandler handler) {
     tcp_acceptor.async_accept(ssl_socket.lowest_layer(), handler);
 }
Exemplo n.º 6
0
		//-----------------------------------------------------------------//
		void start()
		{
			connect_ = false;
			acceptor_.async_accept(socket_,
				boost::bind(&ign_server::on_accept_, this, asio::placeholders::error));
		}