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


C++ endpoint::port方法代码示例

本文整理汇总了C++中tcp::endpoint::port方法的典型用法代码示例。如果您正苦于以下问题:C++ endpoint::port方法的具体用法?C++ endpoint::port怎么用?C++ endpoint::port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcp::endpoint的用法示例。


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

示例1: SimSession

 SimSession(tcp::socket socket, tcp::endpoint peer) :
         start_tp_(hr_clock_t::now()), socket_(std::move(socket)), peer_(std::move(peer)), req_len_(0), res_len_(0) {
     zks::HashCode32 h;
     asio::ip::address peer_addr = peer_.address();
     h += peer_addr.to_string().c_str();
     h += peer_.port();
     session_id_ = zks::to_u8string(h);
     ZKS_INFO(g_logger, session_id_.c_str(), "new session: [%s] from %s:%d started",
             session_id_.c_str(), peer_addr.to_string().c_str(), peer_.port());
 }
开发者ID:jimzshi,项目名称:fw,代码行数:10,代码来源:simproto.cpp

示例2: connect

bool OlsrEventClient::connect(tcp::endpoint& endpoint )
{
    // Synchronous connection to server
    tcp::socket& sock = m_tcpConnection->socket();
    boost::system::error_code error;
    sock.connect ( endpoint,error );
    if (!error)
    {
        DBG_DEV(1,"Connection with OLSR event server established");
        
        m_tcpConnection->async_read ( m_messageRead,
                                      boost::bind ( &OlsrEventClient::handleRead, this,
                                                    boost::asio::placeholders::error )
                                    );
        return true;
    }
    else
    {
        MSG_FAILED("Could not connect to OLSR event server %s on port %d",
          endpoint.address().to_string().c_str(),
          endpoint.port()
        ); 
    
//       std::cerr << "Could not connect to OLSR event server " << 
//                 << " on port " << endpoint.port() << std::endl;

      if (error==boost::asio::error::connection_refused)
      {
        MSG_FAILED("Please verfiy that OLSR server is running and sereadmo plugin is loaded");
        return false;
      }
      else
        throw boost::system::system_error(error);
    }
}
开发者ID:yijiazi,项目名称:mpolsr_testbed,代码行数:35,代码来源:olsreventclient.cpp

示例3: main

int main(int argc, char **argv)
{
    if (argc > 1) 
        if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
            printf("\n    Usage: %s [ThreadCount] [QueryDataLength]\n", argv[0]);
            printf("\n    Default: %s %d 4\n", argv[0], thread_count);
            printf("\n    For example:\n         %s 2 32\n", argv[0]);
            printf("\n    That's means: start server with 2 threads, and per data-package is 32 bytes.\n\n");
            exit(1);
        }

    if (argc > 1)
        thread_count = atoi(argv[1]);
    if (argc > 2)
        qdata = atoi(argv[2]);

    rlimit of = {65536, 65536};
    if (-1 == setrlimit(RLIMIT_NOFILE, &of)) {
        perror("setrlimit");
        exit(1);
    }

    printf("startup server, thread:%d, qdata:%d, listen %s:%d\n", thread_count,
            qdata, addr.address().to_string().c_str(), addr.port());

    echo_server();

    boost::thread_group tg;
    for (int i = 0; i < thread_count; ++i)
        tg.create_thread([]{ ios.run(); });
    tg.join_all();
    return 0;
}
开发者ID:AslayKrys,项目名称:libgo,代码行数:33,代码来源:async_asio_server.cpp

示例4: set_peer

		void set_peer(tcp::endpoint const& ep)
		{
#if TORRENT_USE_IPV6
			is_v6_addr = ep.address().is_v6();
			if (is_v6_addr)
				addr.v6 = ep.address().to_v6().to_bytes();
			else
#endif
				addr.v4 = ep.address().to_v4().to_bytes();
			port = ep.port();
		}
开发者ID:cit,项目名称:libtorrent-peer-idol,代码行数:11,代码来源:torrent_handle.hpp

示例5: addr

	ipv6_peer::ipv6_peer(
		tcp::endpoint const& ep, bool c, int src
	)
		: torrent_peer(ep.port(), c, src)
		, addr(ep.address().to_v6().to_bytes())
	{
		is_v6_addr = true;
#if TORRENT_USE_I2P
		is_i2p_addr = false;
#endif
	}
开发者ID:mildred,项目名称:rasterbar-libtorrent,代码行数:11,代码来源:torrent_peer.cpp

示例6: was_introduced_by

	bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep)
	{
		ut_pex_peer_plugin const* p = static_cast<ut_pex_peer_plugin const*>(pp);
#if TORRENT_USE_IPV6
		if (ep.address().is_v4())
		{
#endif
			ut_pex_peer_plugin::peers4_t::value_type v(ep.address().to_v4().to_bytes(), ep.port());
			ut_pex_peer_plugin::peers4_t::const_iterator i
				= std::lower_bound(p->m_peers.begin(), p->m_peers.end(), v);
			return i != p->m_peers.end() && *i == v;
#if TORRENT_USE_IPV6
		}
		else
		{
			ut_pex_peer_plugin::peers6_t::value_type v(ep.address().to_v6().to_bytes(), ep.port());
			ut_pex_peer_plugin::peers6_t::const_iterator i
				= std::lower_bound(p->m_peers6.begin(), p->m_peers6.end(), v);
			return i != p->m_peers6.end() && *i == v;
		}
#endif
	}
开发者ID:majestrate,项目名称:libtorrent,代码行数:22,代码来源:ut_pex.cpp

示例7:

	inline std::string print_endpoint(tcp::endpoint const& ep)
	{
		error_code ec;
		std::string ret;
		address const& addr = ep.address();
#if TORRENT_USE_IPV6
		if (addr.is_v6())
		{
			ret += '[';
			ret += addr.to_string(ec);
			ret += ']';
			ret += ':';
			ret += to_string(ep.port()).elems;
		}
		else
#endif
		{
			ret += addr.to_string(ec);
			ret += ':';
			ret += to_string(ep.port()).elems;
		}
		return ret;
	}
开发者ID:BlackYoup,项目名称:medusa,代码行数:23,代码来源:socket.hpp

示例8: resolve_address_tcp

static bool resolve_address_tcp(io_service &io, size_t chan, std::string host, unsigned short port, tcp::endpoint &ep)
{
	bool result = false;
	tcp::resolver resolver(io);
	error_code ec;

	tcp::resolver::query query(host, "");
	std::for_each(resolver.resolve(query, ec), tcp::resolver::iterator(),
			[&](const tcp::endpoint & q_ep) {
				ep = q_ep;
				ep.port(port);
				result = true;
				logDebug(PFXd "host %s resolved as %s", chan, host.c_str(), to_string_ss(ep).c_str());
			});

	if (ec) {
		logWarn(PFXd "resolve error: %s", chan, ec.message().c_str());
		result = false;
	}

	return result;
}
开发者ID:FOXTTER,项目名称:mavros,代码行数:22,代码来源:tcp.cpp

示例9: run

    void run(unsigned sleepMillis)
    {
		std::cout << "in GUIMessageSenderThread: run "
                  << sleepMillis << "ms"
                  << std::endl;

		while (running_) {
			if (!connected_) {
				std::cout << "In GUIMessageSenderThread trying to connect to: " << host_ << " " << port_ << std::endl;
				//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
				//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
				endpoint_.address(boost::asio::ip::address::from_string(host_));
				endpoint_.port(port_);
				tcp::acceptor acceptor(*io_service_, endpoint_);

				getClientConnection(acceptor);
				try {
				
					sendMessages(sleepMillis);

					acceptor.close();
					stream_.clear();
					stream_.close();
				}
				catch (std::exception& e)
				{
					std::cerr << "GUIMessageSenderThread Error in connection: " << e.what() << std::endl;
				}
				connected_ = false;
				//boost::asio::deadline_timer timer(*io_service_,boost::posix_time::milliseconds(1000));
				//timer.expires_from_now(boost::posix_time::milliseconds(1000));
				//timer.wait();
			}
		}
		std::cout << "done GUIMessageSenderThread: run "
                  << sleepMillis << "ms"
                  << std::endl;
	}
开发者ID:MakSim345,项目名称:MS-VC08,代码行数:38,代码来源:GUIMessageSenderThread.cpp

示例10: endpoint_to_tuple

tuple endpoint_to_tuple(tcp::endpoint const& ep)
{
    return boost::python::make_tuple(ep.address().to_string(), ep.port());
}
开发者ID:aresch,项目名称:libtorrent,代码行数:4,代码来源:alert.cpp

示例11: if

	// 1. if the IP addresses are identical, hash the ports in 16 bit network-order
	//    binary representation, ordered lowest first.
	// 2. if the IPs are in the same /24, hash the IPs ordered, lowest first.
	// 3. if the IPs are in the ame /16, mask the IPs by 0xffffff55, hash them
	//    ordered, lowest first.
	// 4. if IPs are not in the same /16, mask the IPs by 0xffff5555, hash them
	//    ordered, lowest first.
	//
	// * for IPv6 peers, just use the first 64 bits and widen the masks.
	//   like this: 0xffff5555 -> 0xffffffff55555555
	//   the lower 64 bits are always unmasked
	//
	// * for IPv6 addresses, compare /32 and /48 instead of /16 and /24
	// 
	// * the two IP addresses that are used to calculate the rank must
	//   always be of the same address family
	//
	// * all IP addresses are in network byte order when hashed
	boost::uint32_t peer_priority(tcp::endpoint e1, tcp::endpoint e2)
	{
		TORRENT_ASSERT(e1.address().is_v4() == e2.address().is_v4());

		using std::swap;

		boost::uint32_t ret;
		if (e1.address() == e2.address())
		{
			if (e1.port() > e2.port())
				swap(e1, e2);
			boost::uint32_t p;
			reinterpret_cast<boost::uint16_t*>(&p)[0] = htons(e1.port());
			reinterpret_cast<boost::uint16_t*>(&p)[1] = htons(e2.port());
			ret = crc32c_32(p);
		}
#if TORRENT_USE_IPV6
		else if (e1.address().is_v6())
		{
			const static boost::uint8_t v6mask[][8] = {
				{ 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
			};

			if (e1 > e2) swap(e1, e2);
			address_v6::bytes_type b1 = e1.address().to_v6().to_bytes();
			address_v6::bytes_type b2 = e2.address().to_v6().to_bytes();
			int mask = memcmp(&b1[0], &b2[0], 4) ? 0
				: memcmp(&b1[0], &b2[0], 6) ? 1 : 2;
			apply_mask(&b1[0], v6mask[mask], 8);
			apply_mask(&b2[0], v6mask[mask], 8);
			boost::uint64_t addrbuf[4];
			memcpy(&addrbuf[0], &b1[0], 16);
			memcpy(&addrbuf[2], &b2[0], 16);
			ret = crc32c(addrbuf, 4);
		}
#endif
		else
		{
			const static boost::uint8_t v4mask[][4] = {
				{ 0xff, 0xff, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff }
			};

			if (e1 > e2) swap(e1, e2);
			address_v4::bytes_type b1 = e1.address().to_v4().to_bytes();
			address_v4::bytes_type b2 = e2.address().to_v4().to_bytes();
			int mask = memcmp(&b1[0], &b2[0], 2) ? 0
				: memcmp(&b1[0], &b2[0], 3) ? 1 : 2;
			apply_mask(&b1[0], v4mask[mask], 4);
			apply_mask(&b2[0], v4mask[mask], 4);
			boost::uint64_t addrbuf;
			memcpy(&addrbuf, &b1[0], 4);
			memcpy(reinterpret_cast<char*>(&addrbuf) + 4, &b2[0], 4);
			ret = crc32c(&addrbuf, 1);
		}

		return ret;
	}
开发者ID:mildred,项目名称:rasterbar-libtorrent,代码行数:79,代码来源:torrent_peer.cpp

示例12: if

	// 1. if the IP addresses are identical, hash the ports in 16 bit network-order
	//    binary representation, ordered lowest first.
	// 2. if the IPs are in the same /24, hash the IPs ordered, lowest first.
	// 3. if the IPs are in the ame /16, mask the IPs by 0xffffff55, hash them
	//    ordered, lowest first.
	// 4. if IPs are not in the same /16, mask the IPs by 0xffff5555, hash them
	//    ordered, lowest first.
	//
	// * for IPv6 peers, just use the first 64 bits and widen the masks.
	//   like this: 0xffff5555 -> 0xffffffff55555555
	//   the lower 64 bits are always unmasked
	//
	// * for IPv6 addresses, compare /32 and /48 instead of /16 and /24
	// 
	// * the two IP addresses that are used to calculate the rank must
	//   always be of the same address family
	//
	// * all IP addresses are in network byte order when hashed
	std::uint32_t peer_priority(tcp::endpoint e1, tcp::endpoint e2)
	{
		TORRENT_ASSERT(e1.address().is_v4() == e2.address().is_v4());

		using std::swap;

		std::uint32_t ret;
		if (e1.address() == e2.address())
		{
			if (e1.port() > e2.port())
				swap(e1, e2);
			std::uint32_t p;
#if defined BOOST_BIG_ENDIAN
			p = e1.port() << 16;
			p |= e2.port();
#elif defined BOOST_LITTLE_ENDIAN
			p = aux::host_to_network(e2.port()) << 16;
			p |= aux::host_to_network(e1.port());
#else
#error unsupported endianness
#endif
			ret = crc32c_32(p);
		}
#if TORRENT_USE_IPV6
		else if (e1.address().is_v6())
		{
			static const std::uint8_t v6mask[][8] = {
				{ 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
			};

			if (e1 > e2) swap(e1, e2);
			address_v6::bytes_type b1 = e1.address().to_v6().to_bytes();
			address_v6::bytes_type b2 = e2.address().to_v6().to_bytes();
			int mask = memcmp(&b1[0], &b2[0], 4) ? 0
				: memcmp(&b1[0], &b2[0], 6) ? 1 : 2;
			apply_mask(&b1[0], v6mask[mask], 8);
			apply_mask(&b2[0], v6mask[mask], 8);
			std::uint64_t addrbuf[4];
			memcpy(&addrbuf[0], &b1[0], 16);
			memcpy(&addrbuf[2], &b2[0], 16);
			ret = crc32c(addrbuf, 4);
		}
#endif
		else
		{
			static const std::uint8_t v4mask[][4] = {
				{ 0xff, 0xff, 0x55, 0x55 },
				{ 0xff, 0xff, 0xff, 0x55 },
				{ 0xff, 0xff, 0xff, 0xff }
			};

			if (e1 > e2) swap(e1, e2);
			address_v4::bytes_type b1 = e1.address().to_v4().to_bytes();
			address_v4::bytes_type b2 = e2.address().to_v4().to_bytes();
			int mask = memcmp(&b1[0], &b2[0], 2) ? 0
				: memcmp(&b1[0], &b2[0], 3) ? 1 : 2;
			apply_mask(&b1[0], v4mask[mask], 4);
			apply_mask(&b2[0], v4mask[mask], 4);
			std::uint64_t addrbuf;
			memcpy(&addrbuf, &b1[0], 4);
			memcpy(reinterpret_cast<char*>(&addrbuf) + 4, &b2[0], 4);
			ret = crc32c(&addrbuf, 1);
		}

		return ret;
	}
开发者ID:RealImage,项目名称:libtorrent,代码行数:86,代码来源:torrent_peer.cpp


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