当前位置: 首页>>代码示例>>C++>>正文


C++ resolver::iterator类代码示例

本文整理汇总了C++中tcp::resolver::iterator的典型用法代码示例。如果您正苦于以下问题:C++ iterator类的具体用法?C++ iterator怎么用?C++ iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void session::on_http2_connect_server(const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator)
{
	if (error)
	{
		BOOST_LOG_TRIVIAL(debug) << "[" << session_id << "] " << error.message();
		BOOST_LOG_TRIVIAL(error) << "[" << session_id << "] open " << endpoint_iterator->host_name() << " fail";

		stop();
		return;
	}

	BOOST_LOG_TRIVIAL(debug) << "[" << session_id << "] open " << endpoint_iterator->host_name();

	std::string ack = "HTTP/1.1 200 Connection Established\r\n\r\n";
	write_to_client(ack.c_str(), ack.size(), true);

	boost::asio::streambuf::mutable_buffers_type buf = read_client_buf.prepare(SOCKET_RECV_BUF_LEN);
	client_socket.async_read_some(buf,
		strand_.wrap(
			boost::bind(&session::on_read_client_data, shared_from_this(),
				boost::asio::placeholders::error,
				boost::asio::placeholders::bytes_transferred
			)
		)
	);

	server_socket.async_read_some(boost::asio::buffer(server_buf, SOCKET_RECV_BUF_LEN),
		strand_.wrap(boost::bind(&session::on_read_server_data, shared_from_this(),
			boost::asio::placeholders::error,
			boost::asio::placeholders::bytes_transferred)
		)
	);
}
开发者ID:liuaifu,项目名称:asio5,代码行数:33,代码来源:session_http2.cpp

示例2: close

	void socks4_stream::name_lookup(asio::error_code const& e, tcp::resolver::iterator i
		, boost::shared_ptr<handler_type> h)
	{
		if (e)
		{
			(*h)(e);
			asio::error_code ec;
			close(ec);
			return;
		}

		// SOCKS4 doesn't support IPv6 addresses
		while (i != tcp::resolver::iterator() && i->endpoint().address().is_v6())
			++i;

		if (i == tcp::resolver::iterator())
		{
			asio::error_code ec = asio::error::operation_not_supported;
			(*h)(ec);
			close(ec);
			return;
		}

		m_sock.async_connect(i->endpoint(), boost::bind(
			&socks4_stream::connected, this, _1, h));
	}
开发者ID:naroya,项目名称:fdm,代码行数:26,代码来源:socks4_stream.cpp

示例3: on_name_lookup

void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
{
	if (e == asio::error::operation_aborted) return;
	CHECK_MAGIC;

	if (e)
	{
#ifndef BOOST_NO_EXCEPTIONS
		try {
#endif
			m_callback(e, udp::endpoint(), 0, 0);
#ifndef BOOST_NO_EXCEPTIONS
		} catch(std::exception&) {}
#endif
		return;
	}

	mutex_t::scoped_lock l(m_mutex);	

	m_proxy_addr.address(i->endpoint().address());
	m_proxy_addr.port(i->endpoint().port());
	l.unlock(); // on_connect may be called from within this thread
	m_cc.enqueue(boost::bind(&udp_socket::on_connect, this, _1)
		, boost::bind(&udp_socket::on_timeout, this), seconds(10));
}
开发者ID:dikshie,项目名称:instrumented-rasterbar-libtorrent,代码行数:25,代码来源:udp_socket.cpp

示例4: on_name_lookup

void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
{
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
	TORRENT_ASSERT(m_outstanding_resolve > 0);
	--m_outstanding_resolve;
#endif

	TORRENT_ASSERT(m_outstanding_ops > 0);
	--m_outstanding_ops;
	TORRENT_ASSERT(m_outstanding_ops == m_outstanding_connect
		+ m_outstanding_timeout
		+ m_outstanding_resolve
		+ m_outstanding_connect_queue
		+ m_outstanding_socks);

	if (m_abort) return;
	CHECK_MAGIC;

	if (e == asio::error::operation_aborted) return;

	TORRENT_ASSERT(is_single_thread());

	if (e)
	{
		call_handler(e, udp::endpoint(), 0, 0);

		drain_queue();

		return;
	}

	m_proxy_addr.address(i->endpoint().address());
	m_proxy_addr.port(i->endpoint().port());
	// on_connect may be called from within this thread
	// the semantics for on_connect and on_timeout is 
	// a bit complicated. See comments in connection_queue.hpp
	// for more details. This semantic determines how and
	// when m_outstanding_ops may be decremented
	// To simplyfy this, it's probably a good idea to
	// merge on_connect and on_timeout to a single function

	// on_timeout may be called before on_connected
	// so increment the outstanding ops
	// it may also not be called in case we call
	// connection_queue::done first, so be sure to
	// decrement if that happens
	m_outstanding_ops += 2;

#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
	++m_outstanding_timeout;
	++m_outstanding_connect_queue;
#endif
	m_cc.enqueue(boost::bind(&udp_socket::on_connect, this, _1)
		, boost::bind(&udp_socket::on_timeout, this), seconds(10));
}
开发者ID:miguelfreitas,项目名称:twister-core,代码行数:55,代码来源:udp_socket.cpp

示例5: connect_handler

void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i)
{
	dev::setThreadName("stratum");
	
	if (!ec)
	{
		m_connected = true;
		cnote << "Connected to stratum server " << i->host_name() << ":" << p_active->port;
		if (!p_farm->isMining())
		{
			cnote << "Starting farm";
			if (m_minerType == MinerType::CPU)
				p_farm->start("cpu");
			else if (m_minerType == MinerType::CL)
				p_farm->start("opencl");
			else if (m_minerType == MinerType::CUDA)
				p_farm->start("cuda");
		}
		std::ostream os(&m_requestBuffer);
		os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}\n";

		
		async_write(m_socket, m_requestBuffer,
			boost::bind(&EthStratumClient::handleResponse, this,
									boost::asio::placeholders::error));
	}
	else
	{
		cwarn << "Could not connect to stratum server " << p_active->host << ":" << p_active->port << ", " << ec.message();
		reconnect();
	}

}
开发者ID:Chooka,项目名称:cpp-ethereum,代码行数:33,代码来源:EthStratumClient.cpp

示例6: start_tcp_connect

    bool start_tcp_connect(tcp::resolver::iterator endpoint_iter)
    {
        bool success= true;

        if (endpoint_iter != tcp::resolver::iterator())
        {
            CLIENT_LOG_INFO("ClientNetworkManager::start_tcp_connect") << "Connecting to: " << endpoint_iter->endpoint() << "..." << std::endl;

            // Start the asynchronous connect operation.
            m_tcp_socket.async_connect(
                endpoint_iter->endpoint(),
                boost::bind(&ClientNetworkManagerImpl::handle_tcp_connect, this, _1, endpoint_iter));
        }
        else
        {
            // There are no more endpoints to try. Shut down the client.
            stop();
            success= false;

            if (m_netEventListener)
            {
                m_netEventListener->handle_server_connection_open_failed(boost::asio::error::host_unreachable);
            }
        }

        return success;
    }
开发者ID:Figuration,项目名称:PSMoveService,代码行数:27,代码来源:ClientNetworkManager.cpp

示例7: name_lookup

	void http_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
		, boost::shared_ptr<handler_type> h)
	{
		if (handle_error(e, h)) return;

		m_sock.async_connect(i->endpoint(), boost::bind(
			&http_stream::connected, this, _1, h));
	}
开发者ID:UnitedMarsupials,项目名称:libtorrent,代码行数:8,代码来源:http_stream.cpp

示例8: name_lookup

	void http_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
		, handler_type& h)
	{
		if (handle_error(e, h)) return;

		m_sock.async_connect(i->endpoint(), std::bind(
			&http_stream::connected, this, _1, std::move(h)));
	}
开发者ID:krattai,项目名称:AEBL,代码行数:8,代码来源:http_stream.cpp

示例9: handle_resolve

void websocket::handle_resolve(url target, boost::shared_ptr<tcp::resolver> reslv,
		error_code const& err, tcp::resolver::iterator endpoint_iterator)
{
	if ( check_err(err, "resolve") )
	{
		tcp_conn_->async_connect(endpoint_iterator->endpoint(), boost::bind(&websocket::handle_connect, this,
			target, boost::asio::placeholders::error));
	}
}
开发者ID:aspectron,项目名称:jsx,代码行数:9,代码来源:websocket.cpp

示例10: start_connect

  void start_connect(tcp::resolver::iterator endpoint_iter)
  {
    if (endpoint_iter != tcp::resolver::iterator())
    {
      std::cout << "Trying " << endpoint_iter->endpoint() << "...\n";

      // Set a deadline for the connect operation.
      deadline_.expires_from_now(boost::posix_time::seconds(60));

      // Start the asynchronous connect operation.
      socket_.async_connect(endpoint_iter->endpoint(),
          boost::bind(&client::handle_connect,
            this, _1, endpoint_iter));
    }
    else
    {
      // There are no more endpoints to try. Shut down the client.
      stop();
    }
  }
开发者ID:barrbrain,项目名称:asio,代码行数:20,代码来源:async_tcp_client.cpp

示例11: handle_tcp_connect

    void handle_tcp_connect(
        const boost::system::error_code& ec,
        tcp::resolver::iterator endpoint_iter)
    {
        if (m_connection_stopped)
            return;

        // The async_connect() function automatically opens the socket at the start
        // of the asynchronous operation. If the socket is closed at this time then
        // the timeout handler must have run first.
        if (!m_tcp_socket.is_open())
        {
            CLIENT_LOG_ERROR("ClientNetworkManager::handle_tcp_connect") << "TCP Connect timed out " << std::endl;

            if (m_netEventListener)
            {
                m_netEventListener->handle_server_connection_open_failed(boost::asio::error::timed_out);
            }

            // Try the next available endpoint.
            start_tcp_connect(++endpoint_iter);
        }
        // Check if the connect operation failed before the deadline expired.
        else if (ec)
        {
            CLIENT_LOG_ERROR("ClientNetworkManager::handle_tcp_connect") << "TCP Connect error: " << ec.message() << std::endl;

            if (m_netEventListener)
            {
                m_netEventListener->handle_server_connection_open_failed(ec);
            }

            // We need to close the socket used in the previous connection attempt
            // before starting a new one.
            m_tcp_socket.close();

            // Try the next available endpoint.
            start_tcp_connect(++endpoint_iter);
        }
        // Otherwise we have successfully established a connection.
        else
        {
            tcp::endpoint tcp_endpoint= endpoint_iter->endpoint();

            CLIENT_LOG_INFO("ClientNetworkManager::handle_tcp_connect") << "Connected to " << tcp_endpoint << std::endl;

            // Create a corresponding endpoint udp data will be sent to
            m_udp_server_endpoint= udp::endpoint(tcp_endpoint.address(), tcp_endpoint.port());

            // Start listening for any incoming responses (TCP messages)
            // NOTE: Responses that come independent of a request are a "notification"
            start_tcp_read_response_header();
        }
    }
开发者ID:Figuration,项目名称:PSMoveService,代码行数:54,代码来源:ClientNetworkManager.cpp

示例12: name_lookup

	void http_stream::name_lookup(asio::error_code const& e, tcp::resolver::iterator i
		, boost::shared_ptr<handler_type> h)
	{
		if (e || i == tcp::resolver::iterator())
		{
			(*h)(e);
			close();
			return;
		}

		m_sock.async_connect(i->endpoint(), boost::bind(
			&http_stream::connected, this, _1, h));
	}
开发者ID:codeboost,项目名称:libertv,代码行数:13,代码来源:http_stream.cpp

示例13: TORRENT_ASSERT

	void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
		, handler_type h)
	{
		TORRENT_ASSERT(m_magic == 0x1337);
		if (e || i == tcp::resolver::iterator())
		{
			h(e);
			error_code ec;
			close(ec);
			return;
		}

		ADD_OUTSTANDING_ASYNC("i2p_stream::connected");
		m_sock.async_connect(i->endpoint(), std::bind(
			&i2p_stream::connected, this, _1, std::move(h)));
	}
开发者ID:sudarshan-reddy,项目名称:libtorrent,代码行数:16,代码来源:i2p_stream.cpp

示例14: TORRENT_ASSERT

	void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
		, boost::shared_ptr<handler_type> h)
	{
		TORRENT_ASSERT(m_magic == 0x1337);
		if (e || i == tcp::resolver::iterator())
		{
			(*h)(e);
			error_code ec;
			close(ec);
			return;
		}

#if defined TORRENT_ASIO_DEBUGGING
		add_outstanding_async("i2p_stream::connected");
#endif
		m_sock.async_connect(i->endpoint(), boost::bind(
			&i2p_stream::connected, this, _1, h));
	}
开发者ID:aresch,项目名称:libtorrent,代码行数:18,代码来源:i2p_stream.cpp

示例15: handle_connect

  void handle_connect(const asio::error_code& ec,
      tcp::resolver::iterator endpoint_iter)
  {
    if (stopped_)
      return;

    // The async_connect() function automatically opens the socket at the start
    // of the asynchronous operation. If the socket is closed at this time then
    // the timeout handler must have run first.
    if (!socket_.is_open())
    {
      std::cout << "Connect timed out\n";

      // Try the next available endpoint.
      start_connect(++endpoint_iter);
    }

    // Check if the connect operation failed before the deadline expired.
    else if (ec)
    {
      std::cout << "Connect error: " << ec.message() << "\n";

      // We need to close the socket used in the previous connection attempt
      // before starting a new one.
      socket_.close();

      // Try the next available endpoint.
      start_connect(++endpoint_iter);
    }

    // Otherwise we have successfully established a connection.
    else
    {
      std::cout << "Connected to " << endpoint_iter->endpoint() << "\n";

      // Start the input actor.
      start_read();

      // Start the heartbeat actor.
      start_write();
    }
  }
开发者ID:barrbrain,项目名称:asio,代码行数:42,代码来源:async_tcp_client.cpp


注:本文中的tcp::resolver::iterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。