• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ asio::io_service类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中asio::io_service的典型用法代码示例。如果您正苦于以下问题:C++ io_service类的具体用法?C++ io_service怎么用?C++ io_service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了io_service类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: system_timer_custom_allocation_test

void system_timer_custom_allocation_test()
{
  static asio::io_service io_service;
  struct timer
  {
    asio::system_timer t;
    timer() : t(io_service) {}
  } timers[100];

  int allocation_count = 0;

  for (int i = 0; i < 50; ++i)
  {
    timers[i].t.expires_at((asio::system_timer::time_point::max)());
    timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count));
  }

  for (int i = 50; i < 100; ++i)
  {
    timers[i].t.expires_at((asio::system_timer::time_point::min)());
    timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count));
  }

  for (int i = 0; i < 50; ++i)
    timers[i].t.cancel();

  io_service.run();

  ASIO_CHECK(allocation_count == 0);
}
开发者ID:breese,项目名称:asio,代码行数:30,代码来源:system_timer.cpp


示例2: service_slave

Wondruss::auth_slave::auth_slave(asio::io_service& io_service, Lobby* lobby)
    : service_slave(io_service, lobby)
{
    asio::local::stream_protocol::socket child_fdsock(io_service);
    asio::local::stream_protocol::socket child_rdsock(io_service);
    asio::local::stream_protocol::socket child_wrsock(io_service);
    asio::local::connect_pair(fdsock, child_fdsock);
    asio::local::connect_pair(rdsock, child_wrsock);
    asio::local::connect_pair(wrsock, child_rdsock);
    fcntl(fdsock.native(), F_SETFD, FD_CLOEXEC);
    fcntl(rdsock.native(), F_SETFD, FD_CLOEXEC);
    fcntl(wrsock.native(), F_SETFD, FD_CLOEXEC);
    io_service.notify_fork(asio::io_service::fork_prepare);
    pid_t newpid = fork();
    if (newpid == 0) {
        io_service.notify_fork(asio::io_service::fork_child);
        if(FD_SOCKETS != dup2(child_fdsock.native(), FD_SOCKETS)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        if(FD_LBY_TO_SLV != dup2(child_rdsock.native(), FD_LBY_TO_SLV)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        if(FD_SLV_TO_LBY != dup2(child_wrsock.native(), FD_SLV_TO_LBY)) {
            child_fdsock.send(asio::buffer("KO", 0));
            exit(0);
        }
        // TODO: find wondruss_auth a bit more sanely
        execl("./wondruss_auth", "wondruss_auth", nullptr);
        // if we get here, execl failed for some reason. Let's tell the lobby we failed.
        child_fdsock.send(asio::buffer("KO", 0));
        exit(0);
    }
    io_service.notify_fork(asio::io_service::fork_parent);
    char buf[3] = {0};
    fdsock.receive(asio::buffer(buf, 2)); //TODO: timeout
    if(strcmp(buf, "OK") != 0) {
        LOG_FATAL("Auth process gave us a bad startup msg. WTF?");
        // TODO: fail spectacularly
    } else {
        LOG_INFO("Auth startup OK! continuing...");
    }

    rdsock.async_receive(asio::null_buffers(), std::bind(std::mem_fn(&auth_slave::handle_slave_msg), this, std::placeholders::_1));
}
开发者ID:H-uru,项目名称:Wondruss,代码行数:46,代码来源:auth_slave.cpp


示例3: process_start

    static void process_start(
        const std::error_code& ec,
        asio::io_service& io_service)
      {
      assert(!ec);

      std::shared_ptr<myapp> app(new myapp(io_service));
      io_service.post(std::bind(&myapp::start, app));
      }
开发者ID:nickfajones,项目名称:libapoa,代码行数:9,代码来源:apoaapp_thread.cpp


示例4: process_service_work

void scheduler::process_service_work(asio::io_service& service) {
    while (running) {
        try {
            service.run();
        } catch (std::exception& e) {
            (void) e;
            STATICLIB_PION_LOG_ERROR(log, e.what());
        } catch (...) {
            STATICLIB_PION_LOG_ERROR(log, "caught unrecognized exception");
        }
    }   
}
开发者ID:staticlibs,项目名称:staticlib_httpserver,代码行数:12,代码来源:scheduler.cpp


示例5: Plugin_Quit

void Plugin_Quit()
{
	forwarder->Quit();
	streamManager->quit();

	streamer.release();
	forwarder.release();
	mpdClient.release();
	streamManager.release();

	io_service.stop();
	//::WaitForSingleObject(io_sync_mutex, INFINITE);
}
开发者ID:tilutza,项目名称:out_streamer,代码行数:13,代码来源:out_streamer.cpp


示例6: getLongestPrefixes

void StorageEngineImpl::getLongestPrefixes(asio::io_service &io,
                                           function<void(const std::vector<Name> &)> onCompletion)
{
    // if (!keysTrieBuilt_)
    //     onCompletion(keysTrie_.getLongestPrefixes());
    // else
    // {
    shared_ptr<StorageEngineImpl> me = shared_from_this();
    io.dispatch([me, this, onCompletion]() {
        buildKeyTrie();
        keysTrieBuilt_ = true;
        onCompletion(keysTrie_.getLongestPrefixes());
    });
    // }
}
开发者ID:remap,项目名称:ndnrtc,代码行数:15,代码来源:storage-engine.cpp


示例7: handleConnected

void handleConnected(asio::io_service &ioService, RedisAsyncClient &redis,
        bool ok, const std::string &errmsg)
{
    if( ok )
    {
        redis.command("SET", redisKey, redisValue, [&](const RedisValue &v) {
            std::cerr << "SET: " << v.toString() << std::endl;

            redis.command("GET", redisKey, [&](const RedisValue &v) {
                std::cerr << "GET: " << v.toString() << std::endl;

                redis.command("DEL", redisKey, [&](const RedisValue &) {
                    ioService.stop();
                });
            });
        });
    }
    else
    {
        std::cerr << "Can't connect to redis: " << errmsg << std::endl;
    }
}
开发者ID:caicheng,项目名称:redisclient,代码行数:22,代码来源:async_set_get2.cpp


示例8: reset

 void reset() {
     io_service.reset();
 }
开发者ID:urykhy,项目名称:rpc,代码行数:3,代码来源:WorkQ.hpp


示例9: IOServiceRunThread

DWORD CALLBACK IOServiceRunThread(void *state)
{
	io_service.run();
	::SetEvent(io_sync_mutex);
	return 0;
}
开发者ID:tilutza,项目名称:out_streamer,代码行数:6,代码来源:out_streamer+-+Copy.cpp


示例10: run_ios

void run_ios( ba::io_service &ios )
{
    while( 1 ) {
        ios.run( );
    }
}
开发者ID:newenclave,项目名称:vtrc,代码行数:6,代码来源:main.cpp


示例11: io_service_thread

	void io_service_thread() {
		io_svc.run();
		if(log_level) std::cerr << "io_svc stopped" << std::endl;
		serial.close(); //serial port should be closed from the same thread as io service
	}
开发者ID:stdk,项目名称:u2,代码行数:5,代码来源:asio_mt_impl.cpp


示例12: term

 void term() {
     io_service.stop();
 }
开发者ID:urykhy,项目名称:rpc,代码行数:3,代码来源:WorkQ.hpp


示例13: insert

 void insert(std::function<void(void)> f) {
     io_service.post(f);
 }
开发者ID:urykhy,项目名称:rpc,代码行数:3,代码来源:WorkQ.hpp


示例14: run

 void run(size_t n, ThreadGroup& tg) {
     tg.run([this]{
         asio::io_service::work work(io_service);
         io_service.run();
     }, n);
 }
开发者ID:urykhy,项目名称:rpc,代码行数:6,代码来源:WorkQ.hpp


示例15: ex_flickr

void ex_flickr()
{
    printf ("Tags (default 'kitten'): ");
    std::string tags = util::readLine();

    std::vector<std::string> splitTags;
    boost::split(splitTags, tags, boost::is_space());
    splitTags.resize(
        std::remove(splitTags.begin(), splitTags.end(), "") - splitTags.begin());

    if (splitTags.empty())
        splitTags.push_back("kitten");

    ut::Task<void> task = asyncFlickrDownload(splitTags, 25, 10);

    sIo.run();

    assert(task.isReady());
    try {
        task.get();
    } catch (std::exception& e) {
        printf ("Flickr download failed: %s - %s\n", typeid(e).name(), e.what());
    } catch (...) {
        printf ("Flickr download failed: unknown exception\n");
    }
}
开发者ID:vmilea,项目名称:CppAsync,代码行数:26,代码来源:ex_flickr.cpp


示例16: poll

void Connection::poll()
{
    // reset must always be called prior to poll
    g_ioService.reset();
    g_ioService.poll();
}
开发者ID:Cadyan,项目名称:otclient,代码行数:6,代码来源:connection.cpp


示例17: terminate

void Connection::terminate()
{
    g_ioService.stop();
    m_outputStreams.clear();
}
开发者ID:Cadyan,项目名称:otclient,代码行数:5,代码来源:connection.cpp


示例18:

	virtual ~AsioMTImpl() {
		io_svc.stop();
		io_thread.join();
	}
开发者ID:stdk,项目名称:u2,代码行数:4,代码来源:asio_mt_impl.cpp


示例19: poll

void Connection::poll()
{
    g_ioService.poll();
    g_ioService.reset();
}
开发者ID:DominikMS,项目名称:otclient,代码行数:5,代码来源:connection.cpp


示例20: terminate

void Connection::terminate()
{
    g_ioService.stop();
}
开发者ID:DominikMS,项目名称:otclient,代码行数:4,代码来源:connection.cpp



注:本文中的asio::io_service类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ asmjsmodule::Global类代码示例发布时间:2022-05-31
下一篇:
C++ asio::error_code类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap