Ejemplo n.º 1
0
void protocol::handle_accept(const std::error_code& ec, channel_ptr node,
    acceptor_ptr accept)
{
    accept->accept(
        strand_.wrap(std::bind(&protocol::handle_accept,
            this, _1, _2, accept)));
    if (ec)
    {
        log_error(LOG_PROTOCOL)
            << "Problem accepting connection: " << ec.message();
        return;
    }
    accepted_channels_.push_back(node);
    log_info(LOG_PROTOCOL) << "Accepted connection: "
        << accepted_channels_.size();
    auto handshake_complete = [this, node](const std::error_code& ec)
    {
        if (ec)
        {
            log_error(LOG_PROTOCOL) << "Problem with handshake: "
                << ec.message();
            return;
        }
        // Remove channel from list of connections
        node->subscribe_stop(
            strand_.wrap(std::bind(&protocol::inbound_channel_stopped,
                this, _1, node)));
        setup_new_channel(node);
    };
    handshake_.ready(node, handshake_complete);
}
Ejemplo n.º 2
0
void listening_started(const std::error_code& ec, acceptor_ptr accept)
{
    if (ec)
    {
        log_error() << "Listen: " << ec.message();
        return;
    }
    // Accept first connection.
    accept->accept(
        std::bind(accepted_connection, _1, _2, accept));
}
Ejemplo n.º 3
0
void protocol::handle_listen(const std::error_code& ec, acceptor_ptr accept)
{
    if (ec)
    {
        log_error(LOG_PROTOCOL)
                << "Error while listening: " << ec.message();
    }
    else
    {
        accept->accept(strand_.wrap(
                           &protocol::handle_accept, this, _1, _2, accept));
    }
}
Ejemplo n.º 4
0
void accepted_connection(const std::error_code& ec, channel_ptr node,
    acceptor_ptr accept)
{
    if (ec)
    {
        log_error() << "Accept: " << ec.message();
        return;
    }
    log_info() << "Accepted connection!";
    node->subscribe_stop(node_stopped);
    // Now we need to keep it alive otherwise the connection is closed.
    node->subscribe_version(
        std::bind(version_received, _1, _2, node));
    // Keep accepting more connections.
    accept->accept(
        std::bind(accepted_connection, _1, _2, accept));
}
Ejemplo n.º 5
0
void comm_link::do_accept(acceptor_ptr _acceptor, handler _handler)
{
	BOOST_ASSERT(_handler);
	if(m_state != stopped)
	{
		m_io_service.post(boost::bind(_handler, boost::make_shared<remote_error>
			(remote_error::operation_pending, "another start or stop operation is pending")));
		return;
	}

	if(!_acceptor)
	{
		m_io_service.post(boost::bind(_handler, boost::make_shared<remote_error>
			(remote_error::invalid_endpoint, "null acceptor as parameter")));
		return;
	}

	m_state = starting;
	++m_pending_io;
	m_channel = _acceptor->accept(m_strand.wrap
		(boost::bind(&comm_link::on_connect, this, _1, _handler)));
}
Ejemplo n.º 6
0
void server::start_accept(const acceptor_ptr acceptor, const connection_ptr pconnection)
{
    acceptor->async_accept(pconnection->socket(), pconnection->peer_endpoint(),
                           boost::bind(&server::handle_accept, this,
                                       boost::asio::placeholders::error, acceptor, pconnection));
}
Ejemplo n.º 7
0
void handle_listen(const std::error_code& ec, acceptor_ptr accpt)
{
    acc = accpt;
    acc->accept(handle_accept);
}