本文整理汇总了C++中boost::asio::io_service::dispatch方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::dispatch方法的具体用法?C++ io_service::dispatch怎么用?C++ io_service::dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::io_service
的用法示例。
在下文中一共展示了io_service::dispatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char **argv )
{
// google::InitGoogleLogging(argv[0]);
LOG(INFO) << "main thread " << THIS_THREAD_ID << " running...";
// 如果没有,io_service 执行完了队列中所有缓存的job就退出,在getchar()之前terminating
boost::asio::io_service::work io_work( std::ref(g_io_service) );
boost::thread_group thrgrp;
for (int i = 0; i < 5; ++i)
thrgrp.create_thread( run_io_service );
SLEEP_SECONDS(1);
g_io_service.dispatch( std::bind(job_func, 1) );
getchar();
LOG(INFO) << "Trying to stop io_service...";
// NOTE!!! 如果job_func里用dispatch就停不下来,嵌套
g_io_service.stop();
thrgrp.join_all();
return 0;
}
示例2:
~http_sync_server()
{
error_code ec;
ios_.dispatch(
[&]{ acceptor_.close(ec); });
thread_.join();
}
示例3:
/// Destructor.
~server()
{
work_ = boost::none;
ios_.dispatch([&]
{
error_code ec;
acceptor_.close(ec);
});
for(auto& t : thread_)
t.join();
}
示例4: wlan_event_handler
void wlan_event_handler(const WLAN_NOTIFICATION_DATA& nd, boost::asio::io_service& ios, link_sap::link_sap* ls)
{
std::cout << "wlan notification[" << nd.NotificationCode << "]\n";
if (nd.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM)
return;
switch (nd.NotificationCode) {
case wlan_notification_acm_connection_complete: {
WLAN_CONNECTION_NOTIFICATION_DATA* cnd = reinterpret_cast<WLAN_CONNECTION_NOTIFICATION_DATA*>(nd.pData);
if (cnd->wlanReasonCode == WLAN_REASON_CODE_SUCCESS) {
interface* it = new if_802_11(if_id(&nd.InterfaceGuid));
it->up(true);
MIB_IF_ROW2 it_info = link_sap::win32::get_interface_info(nd.InterfaceGuid);
it->link_addr(odtone::mih::mac_addr(it_info.PhysicalAddress,
it_info.PhysicalAddressLength));
ios.dispatch(boost::bind(&link_sap::link_sap::update, ls, it));
}
}
break;
case wlan_notification_acm_disconnected: {
interface* it = new if_802_11(if_id(&nd.InterfaceGuid));
it->up(false);
MIB_IF_ROW2 it_info = link_sap::win32::get_interface_info(nd.InterfaceGuid);
it->link_addr(odtone::mih::mac_addr(it_info.PhysicalAddress,
it_info.PhysicalAddressLength));
ios.dispatch(boost::bind(&link_sap::link_sap::update, ls, it));
}
}
}
示例5: service_print1
// 将上面的m_strand换成m_service后,
void service_print1()
{
// PRINT_DEBUG("Enter print1");
m_service.dispatch(boost::bind(print, 1));
// PRINT_DEBUG("Exit print1");
}