Beispiel #1
0
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);
}
Beispiel #2
0
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");
    }
}
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");
        }
    }   
}
DWORD CALLBACK IOServiceRunThread(void *state)
{
	io_service.run();
	::SetEvent(io_sync_mutex);
	return 0;
}
Beispiel #5
0
	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
	}
Beispiel #6
0
 void run(size_t n, ThreadGroup& tg) {
     tg.run([this]{
         asio::io_service::work work(io_service);
         io_service.run();
     }, n);
 }
Beispiel #7
0
void run_ios( ba::io_service &ios )
{
    while( 1 ) {
        ios.run( );
    }
}