本文整理汇总了C++中udp::endpoint类的典型用法代码示例。如果您正苦于以下问题:C++ endpoint类的具体用法?C++ endpoint怎么用?C++ endpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了endpoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mib
ManagementClient::ManagementClient(ManagementInformationBase& mib, const udp::endpoint& clientEndpoint, u_int8_t wirelessStateUpdateInterval, u_int8_t locationUpdateInterval, Logger& logger)
: mib(mib), clientEndpoint(clientEndpoint), logger(logger) {
/**
* Check that source port is not an ephemeral port which would
* change every time a client sendto()s to MGMT
*/
if (clientEndpoint.port() >= 32768 && clientEndpoint.port() <= 61000)
logger.error("Client uses an ephemeral port that will change every time it sends data and this will confuse my state management!");
/**
* Initialise state strings map
*/
clientStateStringMap.insert(std::make_pair(ManagementClient::OFFLINE, "OFFLINE"));
clientStateStringMap.insert(std::make_pair(ManagementClient::ONLINE, "ONLINE"));
/**
* Initialise type strings map
*/
clientTypeStringMap.insert(std::make_pair(ManagementClient::UNKNOWN, "Unknown"));
clientTypeStringMap.insert(std::make_pair(ManagementClient::GN, "GeoNetworking"));
clientTypeStringMap.insert(std::make_pair(ManagementClient::FAC, "Facilities"));
clientTypeStringMap.insert(std::make_pair(ManagementClient::LTE, "Long Term Evolution"));
/**
* Initialise this client's state and type
*/
state = ManagementClient::OFFLINE;
type = ManagementClient::UNKNOWN;
/**
* We are not waiting a reply from this client now
*/
repliedToTheLastPacket = true;
}
示例2: wrap
void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec)
{
CHECK_MAGIC;
using namespace libtorrent::detail;
char header[20];
char* h = header;
write_uint16(0, h); // reserved
write_uint8(0, h); // fragment
write_uint8(ep.address().is_v4()?1:4, h); // atyp
write_address(ep.address(), h);
write_uint16(ep.port(), h);
boost::array<asio::const_buffer, 2> iovec;
iovec[0] = asio::const_buffer(header, h - header);
iovec[1] = asio::const_buffer(p, len);
#if TORRENT_USE_IPV6
if (m_proxy_addr.address().is_v4() && m_ipv4_sock.is_open())
#endif
m_ipv4_sock.send_to(iovec, m_proxy_addr, 0, ec);
#if TORRENT_USE_IPV6
else
m_ipv6_sock.send_to(iovec, m_proxy_addr, 0, ec);
#endif
}
示例3: EndpointToString
string EndpointToString(const udp::endpoint &endpoint)
{
string strIp = endpoint.address().to_string();
unsigned int dwPort = endpoint.port();
char szIpPort[32] = {0};
sprintf(szIpPort, "%s:%d", strIp.c_str(), dwPort);
return szIpPort;
}
示例4: node_entry
node_entry(udp::endpoint ep)
: addr(ep.address())
, port(ep.port())
, timeout_count(0xffff)
, rtt(0xffff)
, id(0)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
#endif
}
示例5: invoke
void rpc_manager::invoke(int message_id, udp::endpoint target_addr
, observer_ptr o)
{
INVARIANT_CHECK;
if (m_destructing)
{
o->abort();
return;
}
msg m;
m.message_id = message_id;
m.reply = false;
m.id = m_our_id;
m.addr = target_addr;
TORRENT_ASSERT(!m_transactions[m_next_transaction_id]);
#ifdef TORRENT_DEBUG
int potential_new_id = m_next_transaction_id;
#endif
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
m.transaction_id.clear();
std::back_insert_iterator<std::string> out(m.transaction_id);
io::write_uint16(m_next_transaction_id, out);
o->send(m);
o->sent = time_now();
#if TORRENT_USE_IPV6
o->target_addr = target_addr.address();
#else
o->target_addr = target_addr.address().to_v4();
#endif
o->port = target_addr.port();
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(rpc) << "Invoking " << messages::ids[message_id]
<< " -> " << target_addr;
#endif
m_send(m);
new_transaction_id(o);
#ifndef BOOST_NO_EXCEPTIONS
}
catch (std::exception& e)
{
// m_send may fail with "no route to host"
TORRENT_ASSERT(potential_new_id == m_next_transaction_id);
o->abort();
}
#endif
}
示例6: id
node_entry::node_entry(udp::endpoint ep)
: last_queried(min_time())
, id(0)
, a(ep.address().to_v4().to_bytes())
, p(ep.port())
, rtt(0xffff)
, timeout_count(0xff)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = aux::time_now();
#endif
}
示例7: sendMessage
void DatagramTransceiver::sendMessage(const QString &msg, const udp::endpoint& remote_endpoint)
{
bool write_in_progress = m_write_msgs.empty() == false;
MessageToSend* struct_msg = new MessageToSend;
struct_msg->destination_endpoint.address(remote_endpoint.address());
struct_msg->destination_endpoint.port(remote_endpoint.port());
struct_msg->msg = msg;
m_write_msgs.push_back(struct_msg);
if (write_in_progress == false) doSend();
}
示例8: bind
void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
{
CHECK_MAGIC;
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_abort == false);
if (m_abort)
{
ec = boost::asio::error::operation_aborted;
return;
}
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
#if TORRENT_USE_IPV6
if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec);
#endif
if (ep.address().is_v4())
{
m_ipv4_sock.open(udp::v4(), ec);
if (ec) return;
m_ipv4_sock.bind(ep, ec);
if (ec) return;
udp::socket::non_blocking_io ioc(true);
m_ipv4_sock.io_control(ioc, ec);
if (ec) return;
setup_read(&m_ipv4_sock);
}
#if TORRENT_USE_IPV6
else
{
#ifdef IPV6_V6ONLY
m_ipv6_sock.set_option(v6only(true), ec);
if (ec) return;
#endif
m_ipv6_sock.bind(ep, ec);
if (ec) return;
udp::socket::non_blocking_io ioc(true);
m_ipv6_sock.io_control(ioc, ec);
if (ec) return;
setup_read(&m_ipv6_sock);
}
#endif
#ifdef TORRENT_DEBUG
m_started = true;
#endif
m_bind_port = ep.port();
}
示例9: send
void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec)
{
CHECK_MAGIC;
TORRENT_ASSERT(is_open());
// if the sockets are closed, the udp_socket is closing too
if (!is_open()) return;
if (m_tunnel_packets)
{
// send udp packets through SOCKS5 server
wrap(ep, p, len, ec);
return;
}
if (m_queue_packets)
{
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
qp.ep = ep;
qp.buf.insert(qp.buf.begin(), p, p + len);
return;
}
#if TORRENT_USE_IPV6
if (ep.address().is_v4() && m_ipv4_sock.is_open())
#endif
m_ipv4_sock.send_to(asio::buffer(p, len), ep, 0, ec);
#if TORRENT_USE_IPV6
else
m_ipv6_sock.send_to(asio::buffer(p, len), ep, 0, ec);
#endif
}
示例10: bind
void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
{
CHECK_MAGIC;
mutex_t::scoped_lock l(m_mutex);
TORRENT_ASSERT(m_abort == false);
if (m_abort) return;
if (m_ipv4_sock.is_open()) m_ipv4_sock.close(ec);
#if TORRENT_USE_IPV6
if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec);
#endif
if (ep.address().is_v4())
{
m_ipv4_sock.open(udp::v4(), ec);
if (ec) return;
m_ipv4_sock.bind(ep, ec);
if (ec) return;
if (m_v4_outstanding == 0)
{
++m_v4_outstanding;
m_ipv4_sock.async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
, m_v4_ep, boost::bind(&udp_socket::on_read, this, &m_ipv4_sock, _1, _2));
}
}
#if TORRENT_USE_IPV6
else
{
m_ipv6_sock.set_option(v6only(true), ec);
if (ec) return;
m_ipv6_sock.bind(ep, ec);
if (ec) return;
if (m_v6_outstanding == 0)
{
++m_v6_outstanding;
m_ipv6_sock.async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
, m_v6_ep, boost::bind(&udp_socket::on_read, this, &m_ipv6_sock, _1, _2));
}
}
#endif
#ifdef TORRENT_DEBUG
m_started = true;
#endif
m_bind_port = ep.port();
}
示例11: set_target
void observer::set_target(udp::endpoint const& ep)
{
m_sent = clock_type::now();
m_port = ep.port();
#if TORRENT_USE_IPV6
if (ep.address().is_v6())
{
flags |= flag_ipv6_address;
m_addr.v6 = ep.address().to_v6().to_bytes();
}
else
#endif
{
flags &= ~flag_ipv6_address;
m_addr.v4 = ep.address().to_v4().to_bytes();
}
}
示例12: impl
impl(udp::endpoint endpoint,
Concurrency::ISource<core::monitor::message>& source)
: endpoint_(endpoint)
, socket_(service_, endpoint_.protocol())
, thread_(std::bind(&boost::asio::io_service::run, &service_))
, on_next_([this](const core::monitor::message& msg){ on_next(msg); })
{
source.link_target(&on_next_);
}
示例13: direct_request
void dht_tracker::direct_request(udp::endpoint const& ep, entry& e
, std::function<void(msg const&)> f)
{
#if TORRENT_USE_IPV6
if (ep.protocol() == udp::v6())
m_dht6.direct_request(ep, e, f);
else
#endif
m_dht.direct_request(ep, e, f);
}
示例14: end
broadcast_socket::broadcast_socket(io_service& ios
, udp::endpoint const& multicast_endpoint
, receive_handler_t const& handler
, bool loopback)
: m_multicast_endpoint(multicast_endpoint)
, m_on_receive(handler)
, m_ip_broadcast(false)
{
TORRENT_ASSERT(is_multicast(m_multicast_endpoint.address()));
using namespace asio::ip::multicast;
error_code ec;
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
#if TORRENT_USE_IPV6
if (multicast_endpoint.address().is_v6())
open_multicast_socket(ios, address_v6::any(), loopback, ec);
else
#endif
open_multicast_socket(ios, address_v4::any(), loopback, ec);
for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
, end(interfaces.end()); i != end; ++i)
{
// only multicast on compatible networks
if (i->interface_address.is_v4() != multicast_endpoint.address().is_v4()) continue;
// ignore any loopback interface
if (!loopback && is_loopback(i->interface_address)) continue;
ec = error_code();
open_multicast_socket(ios, i->interface_address, loopback, ec);
#ifndef NDEBUG
// fprintf(stderr, "broadcast socket [ if: %s group: %s ] %s\n"
// , i->interface_address.to_string().c_str()
// , print_address(multicast_endpoint.address()).c_str()
// , ec.message().c_str());
#endif
open_unicast_socket(ios, i->interface_address
, i->netmask.is_v4() ? i->netmask.to_v4() : address_v4());
}
}
示例15: SendData
bool CUDPSocket::SendData(udp::endpoint& ep, char* msg, int size, string& errInfo, unsigned long iProxyIp /*= 0*/, unsigned short iProxyPort /*= 0*/)
{
if(ep.address().to_v4().to_string().empty())
return false;
if(ep.address().to_v4().to_string()=="255.255.255.255")
return false;
if(ep.port() <=0 || ep.port() >65535)
return false;
if(msg == NULL)
return true;
try
{
int ret = this->m_mySocket.send_to(boost::asio::buffer((const void*)msg, size), ep);
if (ret < size)
{
return false;
}
}
catch (const boost::system::error_code& err)
{
ostringstream oss;
oss << "严重错误 CUDPSocket error_code2 " << err.value();
make_log_func_(oss.str());
return false;
}
catch (...)
{
ostringstream oss;
oss << "严重错误...";
make_log_func_(oss.str());
return false;
}
return true;
}