本文整理汇总了C++中boost::asio::ip::udp::endpoint::protocol方法的典型用法代码示例。如果您正苦于以下问题:C++ endpoint::protocol方法的具体用法?C++ endpoint::protocol怎么用?C++ endpoint::protocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::udp::endpoint
的用法示例。
在下文中一共展示了endpoint::protocol方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
udp_stream::udp_stream(
boost::asio::io_service &io_service,
const boost::asio::ip::udp::endpoint &endpoint,
const stream_config &config,
std::size_t buffer_size)
: udp_stream(boost::asio::ip::udp::socket(io_service, endpoint.protocol()),
endpoint, config, buffer_size)
{
}
示例2: socket
blocking_t(const std::string& host, std::uint16_t port) :
io_service(),
socket(io_service)
{
boost::asio::ip::udp::resolver resolver(io_service);
boost::asio::ip::udp::resolver::query query(host, boost::lexical_cast<std::string>(port),
boost::asio::ip::udp::resolver::query::flags::numeric_service);
endpoint = *resolver.resolve(query);
socket.open(endpoint.protocol());
}
示例3: send_to
void udp_multiplexor::send_to(
const boost::asio::ip::udp::endpoint & ep, const char * buf,
const std::size_t & len
)
{
m_bytes_sent += len;
auto uptime = std::time(0) - send_time_;
if (uptime > 0)
{
m_bps_sent = m_bytes_sent / uptime;
log_none("m_bps_sent = " << m_bps_sent);
if (uptime > 1)
{
send_time_ = std::time(0);
uptime = std::time(0) - send_time_;
m_bytes_sent = 0;
}
}
if (ep.protocol() == boost::asio::ip::udp::v4())
{
if (socket_ipv4_.is_open())
{
boost::system::error_code ec;
/**
* Perform a blocking send_to.
*/
socket_ipv4_.send_to(boost::asio::buffer(buf, len), ep, 0, ec);
if (ec)
{
log_debug("UDP v4 send failed " << ec.message() << ".");
if (ec == boost::asio::error::broken_pipe)
{
std::uint16_t port = socket_ipv4_.local_endpoint().port();
close();
open(port);
boost::system::error_code ignored_ec;
/**
* Perform a blocking send_to.
*/
socket_ipv4_.send_to(
boost::asio::buffer(buf, len), ep, 0, ignored_ec
);
}
}
}
}
else
{
if (socket_ipv6_.is_open())
{
boost::system::error_code ec;
/**
* Perform a blocking send_to.
*/
socket_ipv6_.send_to(boost::asio::buffer(buf, len), ep, 0, ec);
if (ec)
{
log_debug("UDP v6 send failed " << ec.message() << ".");
if (ec == boost::asio::error::broken_pipe)
{
std::uint16_t port = socket_ipv6_.local_endpoint().port();
close();
open(port);
boost::system::error_code ignored_ec;
/**
* Perform a blocking send_to.
*/
socket_ipv6_.send_to(
boost::asio::buffer(buf, len), ep, 0, ignored_ec
);
}
}
}
}
}
示例4: send_to
void udp_multiplexor::send_to(
const boost::asio::ip::udp::endpoint & ep, const char * buf,
const std::size_t & len
)
{
/**
* If the length cannot fit within the MTU of the underlying
* datagram protocol we can perform fragmentation and IP-layer
* fragmentation is allowed to the size of 2 Kilobytes.
*/
if (len < 65535)
{
m_bytes_sent += len;
auto uptime = std::time(0) - send_time_;
if (uptime > 0)
{
m_bps_sent = m_bytes_sent / uptime;
log_none("m_bps_sent = " << m_bps_sent);
if (uptime > 1)
{
send_time_ = std::time(0);
uptime = std::time(0) - send_time_;
m_bytes_sent = 0;
}
}
if (ep.protocol() == boost::asio::ip::udp::v4())
{
if (socket_ipv4_.is_open())
{
boost::system::error_code ec;
/**
* Perform a blocking send_to.
*/
socket_ipv4_.send_to(boost::asio::buffer(buf, len), ep, 0, ec);
if (ec)
{
log_debug("UDP v4 send failed " << ec.message() << ".");
if (ec == boost::asio::error::broken_pipe)
{
std::uint16_t port = socket_ipv4_.local_endpoint().port();
close();
open(port);
boost::system::error_code ignored_ec;
/**
* Perform a blocking send_to.
*/
socket_ipv4_.send_to(
boost::asio::buffer(buf, len), ep, 0, ignored_ec
);
}
}
}
}
else
{
if (socket_ipv6_.is_open())
{
boost::system::error_code ec;
/**
* Perform a blocking send_to.
*/
socket_ipv6_.send_to(boost::asio::buffer(buf, len), ep, 0, ec);
if (ec)
{
log_debug("UDP v6 send failed " << ec.message() << ".");
if (ec == boost::asio::error::broken_pipe)
{
std::uint16_t port = socket_ipv6_.local_endpoint().port();
close();
open(port);
boost::system::error_code ignored_ec;
/**
* Perform a blocking send_to.
*/
socket_ipv6_.send_to(
boost::asio::buffer(buf, len), ep, 0, ignored_ec
);
}
}
//.........这里部分代码省略.........