本文整理汇总了C++中boost::asio::io_service::run_one方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::run_one方法的具体用法?C++ io_service::run_one怎么用?C++ io_service::run_one使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::io_service
的用法示例。
在下文中一共展示了io_service::run_one方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: thread_fun
void thread_fun()
{
for (;;)
{
error_code ec;
tcp::endpoint from;
tcp::socket socket(m_ios);
condition_variable cond;
bool done = false;
m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
while (!done)
{
m_ios.run_one();
m_ios.reset();
}
if (ec == boost::asio::error::operation_aborted
|| ec == boost::asio::error::bad_descriptor) return;
if (ec)
{
fprintf(stderr, "Error accepting connection on peer socket: %s\n", ec.message().c_str());
return;
}
fprintf(stderr, "%s: incoming peer connection\n", time_now_string());
++m_peer_requests;
socket.close(ec);
}
}
示例2: run_service
inline void run_service( boost::asio::io_service & io_service) {
h_timer timer( io_service, boost::chrono::seconds(0) );
timer.async_wait( boost::bind( timer_handler, boost::ref( timer) ) );
while (true)
{
boost::system::error_code ec;
std::size_t num = io_service.run_one(ec);
if (num == 0)
{
return;
}
boost::this_fiber::yield();
}
}
示例3: thread_fun
void thread_fun()
{
char buffer[2000];
for (;;)
{
error_code ec;
udp::endpoint from;
size_t bytes_transferred;
bool done = false;
m_socket.async_receive_from(
asio::buffer(buffer, sizeof(buffer)), from, 0
, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
while (!done)
{
m_ios.run_one();
m_ios.reset();
}
if (ec == boost::asio::error::operation_aborted
|| ec == boost::asio::error::bad_descriptor) return;
if (ec)
{
fprintf(stderr, "Error receiving on DHT socket: %s\n", ec.message().c_str());
return;
}
try
{
entry msg = bdecode(buffer, buffer + bytes_transferred);
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
std::cerr << msg << std::endl;
#endif
++m_dht_requests;
}
catch (std::exception& e)
{
fprintf(stderr, "failed to decode DHT message: %s\n", e.what());
}
}
}
示例4: IdleService
static inline void avloop_run(boost::asio::io_service& io_service)
{
using namespace ::detail;
if (!boost::asio::has_service<IdleService>(io_service))
boost::asio::add_service(io_service, new IdleService(io_service));
while (!io_service.stopped())
{
if(!boost::asio::use_service<IdleService>(io_service).has_idle())
{
if (!io_service.run_one())
break;
}
else
{
while (io_service.poll());
// 执行 idle handler!
boost::asio::use_service<IdleService>(io_service).poll_one();
}
}
}
示例5: service
service( boost::asio::io_service & io_svc) :
boost::asio::io_service::service( io_svc),
work_{ new boost::asio::io_service::work( io_svc) } {
io_svc.post([&io_svc](){
//]
//[asio_rr_service_lambda
while ( ! io_svc.stopped() ) {
if ( boost::fibers::has_ready_fibers() ) {
// run all pending handlers in round_robin
while ( io_svc.poll() );
// run pending (ready) fibers
this_fiber::yield();
} else {
// run one handler inside io_service
// if no handler available, block this thread
if ( ! io_svc.run_one() ) {
break;
}
}
}
//]
//[asio_rr_service_bottom
});
}