本文整理汇总了C++中udp::endpoint::address方法的典型用法代码示例。如果您正苦于以下问题:C++ endpoint::address方法的具体用法?C++ endpoint::address怎么用?C++ endpoint::address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类udp::endpoint
的用法示例。
在下文中一共展示了endpoint::address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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;
}
示例5: 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();
}
}
示例6: 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());
}
}
示例7: addr
node_entry(node_id const& id_, udp::endpoint ep, int roundtriptime = 0xffff, bool pinged = false)
: addr(ep.address())
, port(ep.port())
, timeout_count(pinged ? 0 : 0xffff)
, rtt(roundtriptime)
, id(id_)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
#endif
}
示例8: 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;
}
示例9: 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
}
示例10: 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();
}
示例11: set_target
void observer::set_target(udp::endpoint const& ep)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
// use high resolution timers for logging
m_sent = time_now_hires();
#else
m_sent = time_now();
#endif
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: 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();
}
示例13: 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();
}
示例14: Connection
//==============================================================================
// Handle Connection (uglysolution.com)
// - Checks if the connection already exists. If it exists, restart timeout timer.
// Else, add new connection.
//==============================================================================
boost::shared_ptr<Connection> ConnectionHandler::handleConnection( udp::endpoint& _endpoint )
{
unsigned int connection_size = m_connections.size();
// Check if the connection already exists
for( unsigned int i = 0; i < connection_size; i++ )
{
if( m_connections[i]->endpoint.address().to_string().compare(_endpoint.address().to_string()) == 0 && m_connections[i]->endpoint.port() == _endpoint.port() )
{
boost::shared_ptr<Connection> connection = m_connections[i];
connection->timout_timer.expires_from_now( boost::posix_time::seconds(TIMEOUT) );
connection->timout_timer.async_wait( boost::bind(&ConnectionHandler::timeout, this, connection, boost::asio::placeholders::error) );
return m_connections[i];
}
}
// Check if connection size is greater than the allowed amount of connections
if( connection_size >= MAX_CONNECTIONS )
return boost::shared_ptr<Connection>();
// Find an connection ID
m_id_counter++;
for( unsigned int i = 0; i < m_connections.size(); i++ )
{
if( m_connections[i]->connection_id == m_id_counter )
{
m_id_counter++;
i = 0;
}
}
// Add the connection and start the timers
boost::shared_ptr<Connection> new_connection( new Connection(m_id_counter, _endpoint, (*m_io_service)) );
new_connection->ack_timer.async_wait( boost::bind(&ConnectionHandler::requestAck, this, new_connection, boost::asio::placeholders::error) );
new_connection->timout_timer.async_wait( boost::bind(&ConnectionHandler::timeout, this, new_connection, boost::asio::placeholders::error) );
m_connections.push_back( new_connection );
// temp solution
if( m_network_handler->isServer() )
new_connection->sync_timer.async_wait( boost::bind(&ConnectionHandler::syncClock, this, new_connection, boost::asio::placeholders::error) );
return m_connections.back();
}
示例15: send_packet
bool dht_tracker::send_packet(entry& e, udp::endpoint const& addr)
{
static char const version_str[] = {'L', 'T'
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR
};
e["v"] = std::string(version_str, version_str + 4);
m_send_buf.clear();
bencode(std::back_inserter(m_send_buf), e);
// update the quota. We won't prevent the packet to be sent if we exceed
// the quota, we'll just (potentially) block the next incoming request.
m_send_quota -= int(m_send_buf.size());
error_code ec;
m_send_fun(addr, m_send_buf, ec, 0);
if (ec)
{
m_counters.inc_stats_counter(counters::dht_messages_out_dropped);
#ifndef TORRENT_DISABLE_LOGGING
m_log->log_packet(dht_logger::outgoing_message, m_send_buf, addr);
#endif
return false;
}
m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size());
// account for IP and UDP overhead
m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes
, addr.address().is_v6() ? 48 : 28);
m_counters.inc_stats_counter(counters::dht_messages_out);
#ifndef TORRENT_DISABLE_LOGGING
m_log->log_packet(dht_logger::outgoing_message, m_send_buf, addr);
#endif
return true;
}