本文整理汇总了C++中boost::asio::io_service::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::poll方法的具体用法?C++ io_service::poll怎么用?C++ io_service::poll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::io_service
的用法示例。
在下文中一共展示了io_service::poll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
SerialPort port(
"/dev/tty.usbmodemfa1311",
// "/dev/tty.usbmodemfa141",
57600, iosrv,
[](std::vector<uint8_t>& data) { on_serial_data_receive(data); });
ba::deadline_timer timer(iosrv, boost::posix_time::seconds(1));
std::function<void(boost::system::error_code const&)> on_timeout;
auto relauch_timer = [&]() { timer.async_wait(on_timeout); };
on_timeout = [&](boost::system::error_code const&)
{
on_timer(port);
timer.expires_from_now(period);
relauch_timer();
};
relauch_timer();
while(true)
{
iosrv.poll();
}
return 0;
}
示例2: run_event_loop_until_connect
void run_event_loop_until_connect()
{
while (!last_error && !is_connected) {
service.poll();
service.reset();
check_if_timed_out();
}
}
示例3: run_event_loop_until_frame_received
void run_event_loop_until_frame_received()
{
using boost::bind;
have_frame = false;
buffer.consume(buffer.size());
last_error = boost::system::error_code();
boost::asio::async_read_until(socket,
buffer,
"END\r\n",
bind(&TimedSessionBase::handle_frame_reception,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
service.reset();
while (!last_error && !have_frame) {
service.poll();
service.reset();
check_if_timed_out();
}
}
示例4: work
// MsgWaitForMultipleObjectsEx 集成进去.
static inline void avloop_run_gui(boost::asio::io_service& io_service)
{
using namespace ::detail;
boost::asio::io_service::work work(io_service);
if (!boost::asio::has_service<IdleService>(io_service))
boost::asio::add_service(io_service, new IdleService(io_service));
if (!boost::asio::has_service<Win32MsgLoopService>(io_service))
boost::asio::add_service(io_service, new Win32MsgLoopService(io_service));
while (!io_service.stopped())
{
// 首先处理 asio 的消息.
while (io_service.poll())
{
// 然后执行 gui 循环,看有没有 gui 事件.
if (boost::asio::use_service<Win32MsgLoopService>(io_service).has_message())
{
// 执行以下.
boost::asio::use_service<Win32MsgLoopService>(io_service).poll_one();
}
}
// 然后执行 gui 循环,看有没有 gui 事件.
while(boost::asio::use_service<Win32MsgLoopService>(io_service).has_message())
{
// 执行以下.
boost::asio::use_service<Win32MsgLoopService>(io_service).poll_one();
}
// 执行 idle handler!
if (boost::asio::use_service<IdleService>(io_service).has_idle())
boost::asio::use_service<IdleService>(io_service).poll_one();
// 都没有事件了,执行 一次 1ms 的超时等待.
auto ret = MsgWaitForMultipleObjectsEx(0, nullptr, 1, QS_ALLEVENTS, MWMO_WAITALL|MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
// 可能是有 gui 消息了, 呵呵, 从头来吧.
}
}
示例5: 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();
}
}
}
示例6: 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
});
}
示例7: run_01
//---------------------------------------------------------
void run_01(boost::asio::io_service& io_service, boost::thread::id id)
{
io_service.post(boost::bind(check_thread_id_01, id));
io_service.post(boost::bind(check_thread_id_00, boost::this_thread::get_id()));
io_service.poll();
}
示例8: poll
void poll()
{
io_service_.poll();
}
示例9: Poll
void Connection::Poll()
{
netservice.poll();
}
示例10:
Connection::~Connection()
{
sock.close();
netservice.poll();
netservice.reset();
}