コード例 #1
0
void cia_client::do_timeout_check()
{
	if (m_started_)
	{
		m_check_timeout_timer.expires_from_now(boost::posix_time::milliseconds(TIMEOUT_CHECK_ELAPSED));
		ptr self = shared_from_this();
		//BOOST_LOG_SEV(cia_g_logger, AllEvent) << "开始准备异步检测超时, 触发检测的时间是在"
		//	<< TIMEOUT_CHECK_ELAPSED << "毫秒后, " << "客户端socket超时时间设置为" << m_timeout_elapsed << "毫秒";
		m_check_timeout_timer.async_wait([this, self](const error_code& ec){
			if (ec)
			{
				BOOST_LOG_SEV(cia_g_logger, Debug) << "已停止超时检测";
				stop();
				return;
			}
			std::size_t elapsed_time_ = std::size_t(m_update_time.elapsed().wall / 1000000);
			if (elapsed_time_ > m_timeout_elapsed) {
				BOOST_LOG_SEV(cia_g_logger, Debug) << "客户端因超时关闭, 已经在"
					<< elapsed_time_ << "毫秒内无任何动作";
				stop();
			}
			else if (elapsed_time_ > m_timeout_elapsed / 2) {
				BOOST_LOG_SEV(cia_g_logger, AllEvent) << "向客户端发送心跳请求, 已经在"
					<< elapsed_time_ << "毫秒内无任何动作";
				do_deal_heart_request();
			}
			do_timeout_check();
		});
	}
}
コード例 #2
0
ファイル: main.cpp プロジェクト: hmkwizu/push_service
void on_timer_good(deadline_timer& t, push_service& ps)
{
    static uint32_t count = 10000;

    device dev1(apns::key, base64_decode("9pfzxPgLrG/8DM8zYXcwUEId2lH0G8dq+jlkh72HXMQ="));
    apns_message msg;

    msg.alert = "Valid";
    msg.badge = 3;
    msg.sound = "chime";

    msg.action_loc_key = "test";
    msg.loc_key = "test2";
    msg.loc_args.push_back("test12");
    msg.loc_args.push_back("test23");

    msg.launch_image = "test.png";
    msg.add("custom-test", "hello world"); // custom key-value

//    ps.post(dev1, msg, 1, count++);


    // reset timer
    t.expires_from_now(posix_time::millisec(1));
    t.async_wait(boost::bind(&on_timer_good, boost::ref(t), boost::ref(ps)));
}
コード例 #3
0
ファイル: main.cpp プロジェクト: forging2012/bootstrap-dht
void print_stats(deadline_timer& stats_timer, error_code const& ec)
{
	if (ec) return;

	time_point now = steady_clock::now();
	float interval = duration_cast<milliseconds>(now - stats_start).count() / 1000.f;
	if (interval <= 0.f) interval = 0.001f;
	stats_start = now;

	printf(
#ifdef DEBUG_STATS
		"ping-queue: %" PRId64 "m"
		" node-buf: [%dk %dk %dk %dk]"
#endif

		" in: %.1f"
		" invalid_enc: %.1f"
		" invalid_src: %.1f"
		" id_failure: %.1f"
		" out_ping: %.1f"
		" short_tid_pong: %.1f"
		" invalid_pong: %.1f"
		" added: %.1f\n"
#ifdef DEBUG_STATS
		, queue_time.load()
		, nodebuf_size[0].load() / 1000
		, nodebuf_size[1].load() / 1000
		, nodebuf_size[2].load() / 1000
		, nodebuf_size[3].load() / 1000
#endif
		, incoming_queries.exchange(0) / interval
		, invalid_encoding.exchange(0) / interval
		, invalid_src_address.exchange(0) / interval
		, failed_nodeid_queries.exchange(0) / interval
		, outgoing_pings.exchange(0) / interval
		, short_tid_pongs.exchange(0) / interval
		, invalid_pongs.exchange(0) / interval
		, added_nodes.exchange(0) / interval
		);

#ifdef CLIENTS_STAT
	std::lock_guard<std::mutex> l(client_mutex);
	std::vector<std::pair<int, uint16_t>> ordered;
	for (auto i : client_histogram) {
		ordered.emplace_back(i.second, i.first);
	}
	std::sort(ordered.begin(), ordered.end());
	for (auto i : ordered) {
		printf("[%c%c: %d] ", (i.second >> 8) & 0xff, i.second & 0xff, i.first);
	}
	printf("\n");
	client_histogram.clear();
#endif

	fflush(stdout);

	stats_timer.expires_from_now(boost::posix_time::seconds(print_stats_interval));
	stats_timer.async_wait(std::bind(&print_stats, std::ref(stats_timer), _1));
}
コード例 #4
0
ファイル: main.cpp プロジェクト: hmkwizu/push_service
void on_timer_bad(deadline_timer& t, push_service& ps)
{
    static uint32_t count = 1;

    device dev1(apns::key, base64_decode("9pfzxPgLrG/8DM8zYXcwUEId2lH0G8dq+jlkh72HXMQ="));
    //  ps.post(dev1, "", 1, count++);

    // reset timer
    t.expires_from_now(posix_time::millisec(10));
    t.async_wait(boost::bind(&on_timer_bad, boost::ref(t), boost::ref(ps)));
}
コード例 #5
0
ファイル: resolve.hpp プロジェクト: AstroProfundis/Boost.DNS
        void
        send_packet ()
        {
          // 2 seconds should be a good time to wait for a response.
          retry_timer.expires_from_now(boost::posix_time::seconds(2));
          retry_timer.async_wait(boost::bind(&resolve::resend_timeout, this));

          // send out the packets for request
          for( vector< ip::udp::endpoint >::iterator iter = endpointList.begin(); iter != endpointList.end(); ++iter )
            socket.send_to(boost::asio::buffer(reqBuffer.get_array()), *iter);
        }
コード例 #6
0
ファイル: resolve.hpp プロジェクト: AstroProfundis/Boost.DNS
        /**
         @param qmessage Query message to send to the server list
         @return Query result. If the query failed or timed out, dns::message.result() will return no_result.
         */
        dns::message &
        query ( dns::message & qmessage )
        {
          // set a few defaults for a message
          qmessage.recursive(true);
          qmessage.action(dns::message::query);
          qmessage.opcode(dns::message::squery);

          // make our message id unique
          qmessage.id(0xaffe);

          qmessage.encode(reqBuffer);

          // in the event nothing get's resolved, answer with the original question
          responseMessage = qmessage;
          responseMessage.result(dns::message::no_result);

          // die if we don't get a response within death_timeout
          death_timer.expires_from_now(boost::posix_time::seconds(death_timeout));
          death_timer.async_wait(boost::bind(&resolve::request_timeout, this));

          for( vector< ip::udp::endpoint >::iterator iter = endpointList.begin(); iter != endpointList.end(); ++iter )
          {
            // we're waiting for N of requests
            requestCount.inc();

            // setup the receive buffer
            shared_dns_buffer_t recvBuffer(new dns_buffer_t);
            socket.async_receive_from(boost::asio::buffer(recvBuffer.get()->get_array()), *iter, boost::bind(
                &resolve::handle_recv,
                this,
                recvBuffer,
                boost::asio::placeholders::error,
                boost::asio::placeholders::bytes_transferred));
          }

          // kick off the request
          send_packet();

          // run a blocking service
          ioservice.run();

          return responseMessage;
        }
コード例 #7
0
ファイル: main.cpp プロジェクト: hmkwizu/push_service
void on_gcm_timer_good(deadline_timer& t, gcm& google)
{
    static uint32_t count = 10000;

    device dev(gcm::key, "APA91bGKcd_PZQ9eYqo4INvuCdqFX96xnSS6B12i66H0"
               "-6Mj3OJf57YUmEStuahZjYjroFsd4wR31n45bknh2xGjM0BftQ8zccLVF3"
               "GhwwAO8MMd4ldq_TO0LwmAwSvhczig74j0s_ABzZKWHFtkQKzHkALshScbhg");

    gcm_message msg(count++);
    msg.dry_run = true;
    msg.time_to_live = 1234;

    msg.add("custom", boost::lexical_cast<std::string>(count) );

    google.post(dev, msg, 0);

    // reset timer
    t.expires_from_now(posix_time::millisec(1));
    t.async_wait(boost::bind(&on_gcm_timer_good, boost::ref(t), boost::ref(google)));
}
コード例 #8
0
ファイル: pool_timer.cpp プロジェクト: brycelelbach/hpx
    bool pool_timer::start(util::steady_duration const& time_duration,
        bool evaluate_)
    {
        std::unique_lock<mutex_type> l(mtx_);
        if (is_terminated_)
            return false;

        if (!is_started_) {
            if (first_start_) {
                first_start_ = false;

                util::unlock_guard<std::unique_lock<mutex_type> > ul(l);
                if (pre_shutdown_)
                {
                    register_pre_shutdown_function(
                        util::bind(&pool_timer::terminate,
                            this->shared_from_this()));
                }
                else
                {
                    register_shutdown_function(
                        util::bind(&pool_timer::terminate,
                            this->shared_from_this()));
                }
            }

            is_stopped_ = false;
            is_started_ = true;

            HPX_ASSERT(timer_ != nullptr);
            timer_->expires_from_now(time_duration.value());
            timer_->async_wait(util::bind(&pool_timer::timer_handler,
                this->shared_from_this(), util::placeholders::_1));

            return true;
        }
        return false;
    }