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");
    }
}
Beispiel #3
0
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));
}
Beispiel #4
0
    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));
      }
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");
        }
    }   
}
Beispiel #6
0
void Plugin_Quit()
{
	forwarder->Quit();
	streamManager->quit();

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

	io_service.stop();
	//::WaitForSingleObject(io_sync_mutex, INFINITE);
}
Beispiel #7
0
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());
    });
    // }
}
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;
    }
}
Beispiel #9
0
 void reset() {
     io_service.reset();
 }
DWORD CALLBACK IOServiceRunThread(void *state)
{
	io_service.run();
	::SetEvent(io_sync_mutex);
	return 0;
}
Beispiel #11
0
void run_ios( ba::io_service &ios )
{
    while( 1 ) {
        ios.run( );
    }
}
Beispiel #12
0
void Connection::poll()
{
    // reset must always be called prior to poll
    g_ioService.reset();
    g_ioService.poll();
}
Beispiel #13
0
void Connection::terminate()
{
    g_ioService.stop();
    m_outputStreams.clear();
}
Beispiel #14
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 #15
0
	virtual ~AsioMTImpl() {
		io_svc.stop();
		io_thread.join();
	}
Beispiel #16
0
void Connection::poll()
{
    g_ioService.poll();
    g_ioService.reset();
}
Beispiel #17
0
void Connection::terminate()
{
    g_ioService.stop();
}
Beispiel #18
0
 void term() {
     io_service.stop();
 }
Beispiel #19
0
 void insert(std::function<void(void)> f) {
     io_service.post(f);
 }
Beispiel #20
0
 void run(size_t n, ThreadGroup& tg) {
     tg.run([this]{
         asio::io_service::work work(io_service);
         io_service.run();
     }, n);
 }