Пример #1
0
 void Wait() {
     if (!queue_.empty()) {
         std::cout << "t0 + " << std::setw(4) << mark() << "ms Open for Number :   "  << type <<  " (dur:"  << queue_.front() <<  ") (depth " << queue_.size() << ")\n";
         timer_.expires_from_now(boost::posix_time::milliseconds(queue_.front()));
         timer_.async_wait(strand_.wrap(std::bind(&Session::Close, shared_from_this())));
     }
 }
Пример #2
0
inline void set_timer(io::deadline_timer& timer, uint64_t milliseconds,
                      Handler&& handler) {
  if (milliseconds != length_framed_connection::no_deadline) {
    timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
    timer.async_wait(std::forward<Handler>(handler));
  }
}
Пример #3
0
//---------------------------------------------------------
void handle_timer(boost::asio::deadline_timer& timer, const boost::system::error_code& ec)
{
	std::cout<<"*"<<std::flush;

	timer.expires_from_now(boost::posix_time::seconds(1)); ///!\ important /!\ got to be reset
	timer.async_wait(boost::bind(handle_timer, boost::ref(timer), boost::asio::placeholders::error));
}
Пример #4
0
	void start(FIFO_TYPE *audiofifo) {
		m_audiofifo = audiofifo;
		if(running)
			return;
		timer.expires_from_now(boost::posix_time::seconds(2));
		timer.async_wait(timeout_handler);
	}
Пример #5
0
		static void check_interrupt( boost::asio::deadline_timer& c )
		{
			if( boost::this_thread::interruption_requested() ) 
				throw std::runtime_error("Thread interrupted.");
			c.expires_from_now( boost::posix_time::seconds(1) );
			c.async_wait( boost::bind( &listener::check_interrupt, boost::ref(c) ) );
		}
Пример #6
0
void print(const boost::system::error_code& e)
{
	std::cout << i++ << ": Hello, world!\n";
	std::cout << e << std::endl;
	t.expires_from_now(boost::posix_time::seconds(1));
	t.async_wait(print);
}
Пример #7
0
  void do_timer(const boost::system::error_code&)
  {
    callback();

    // reset the timer
    timer.expires_from_now(checkpoint_interval);
    timer.async_wait(boost::bind(&handlers::do_timer, this, _1));
  }
Пример #8
0
 void reconnect() {
     if (m_abort || m_reconnect_secs <= 0)
         return;
     m_reconnect_timer.expires_from_now(boost::posix_time::seconds(m_reconnect_secs));
     m_reconnect_timer.async_wait(
         boost::bind(&self::timer_reconnect, this->shared_from_this(),
                     boost::asio::placeholders::error));
 }
Пример #9
0
void Print::print() {
    if (count_ < 5) {
        timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
        timer_.async_wait(boost::bind(&Print::print, this));
    }
    std::cout << "wait count " << count_ << std::endl;    
    count_++;
}
Пример #10
0
 void justdoit()
 {
     rc_->get(strand_.wrap(
         boost::bind(&tormoz_get::handle_done, shared_from_this(), _1, _2))
              );
     timer_.expires_from_now(boost::posix_time::milliseconds(100));
     timer_.async_wait(strand_.wrap(boost::bind(&tormoz_get::handle_timeout, shared_from_this(), _1)));
 }
Пример #11
0
 void on_open() override {
     auto self(shared_from_this());
     std::cout << "WebSocket connection open\n";
     timer_.expires_from_now(boost::posix_time::milliseconds(100));
     timer_.async_wait([this, self](const boost::system::error_code &ec) {
         timer_cb(ec);
     });
 }
Пример #12
0
    void start_timer(){
        ping_timer->expires_at(ping_timer->expires_at() + ping_interval);
        ping_timer->async_wait(boost::bind(
            &sAudioReceiver::handle_timer,
            this,
            boost::asio::placeholders::error
        ));

    }
 void deadlineCallback(boost::asio::deadline_timer& t, udp::socket& s)
 {
   if (t.expires_at() <= boost::asio::deadline_timer::traits_type::now())
   {
     s.cancel();
     t.expires_at(boost::posix_time::pos_infin);
   }
   t.async_wait(boost::bind(&CompactRIOCommunicationNode::deadlineCallback, this, boost::ref(t), boost::ref(s)));
 }
Пример #14
0
void PionScheduler::keepRunning(boost::asio::io_service& my_service,
								boost::asio::deadline_timer& my_timer)
{
	if (m_is_running) {
		// schedule this again to make sure the service doesn't complete
		my_timer.expires_from_now(boost::posix_time::seconds(KEEP_RUNNING_TIMER_SECONDS));
		my_timer.async_wait(boost::bind(&PionScheduler::keepRunning, this,
										boost::ref(my_service), boost::ref(my_timer)));
	}
}
Пример #15
0
 void call_func(const boost::system::error_code&)
 {
     if (count >= count_max)
         return;
     ++count;
     f();
     t.expires_at(t.expires_at() + boost::posix_time::millisec(500));
     t.async_wait(boost::bind(&a_timer::call_func, this,
                              boost::asio::placeholders::error));
 }
Пример #16
0
void Detection::HandleReceiveFrom(int packet_type, int tracker_index, boost::asio::deadline_timer& timer,
                                  const boost::system::error_code& error, size_t bytes_recvd)
{
    std::ofstream fout("text.txt", std::ofstream::ate|std::ofstream::app);
    if (!error || error == boost::asio::error::message_size)
    {
        if (packet_type == 0)  // bs
        {
            int tracker_count = data_[14] * 256 + data_[13];
            fout << "向bs查询到" << tracker_count << "个tracker" << std::endl;
            fout.close();
            has_tracker_list = true;
            timer.cancel();
        }
        else if (packet_type == 1)  // tracker
        {
            int peer_count = data_[28] * 256 + data_[27];
            //mu.lock();
            std::string result = "";
            result.append("向tracker(");
            result.append(m_tracker_infos[tracker_index].ip);
            result.append(":");
            boost::uint16_t port = m_tracker_infos[tracker_index].port;
            char tmp[10];
            itoa(m_tracker_infos[tracker_index].port, tmp, 10);
            result.append(tmp);
            result.append( ")查询到");
            itoa(peer_count, tmp, 10);
            result.append(tmp);
            result.append("个peer");
//             result += "向tracker(" + m_tracker_infos[tracker_index].ip + ":" + m_tracker_infos[tracker_index].port
//                 + ")查询到" + peer_count + "个peer";
            result_trackers.push_back(result);
//             fout << "向tracker(" << m_tracker_infos[tracker_index].ip << ":" << m_tracker_infos[tracker_index].port
//                 << ")查询到" << peer_count << "个peer" << std::endl;
//             fout.close();
//             mu.unlock();
            timer.cancel();
            has_peer_list = true;
        }
    }
    else if (error != boost::asio::error::operation_aborted)
    {
        if (packet_type == 0)
        {
            fout << error.message() << std::endl;
            fout.close();
        }
        else if (packet_type == 1)
        {
            result_trackers.push_back(error.message());
        }
        
    }
}
Пример #17
0
void SenderImpl::scheduleTimer(Sender_weak weak)
{
    namespace ptime = boost::posix_time;

    m_timer.expires_at(m_timer.expires_at() +
            ptime::milliseconds(m_config->period()));

    m_timer.async_wait(
            boost::bind(&SenderImpl::handleTimeout,
                this, weak, _1));
}
Пример #18
0
 handlers(boost::asio::io_service& io_service, std::function<void()> callback)
   : callback(callback)
   , signals(io_service, SIGHUP, SIGTERM, SIGINT)
   , timer(io_service)
   , checkpoint_interval(boost::posix_time::hours(1))
 {
   signals.async_wait(boost::bind(&handlers::do_signal, this, _1, _2));
   // set the timer
   timer.expires_from_now(checkpoint_interval);
   timer.async_wait(boost::bind(&handlers::do_timer, this, _1));
 }
Пример #19
0
    void print() {
        if (m_count >= 5)
            return;

        std::cout << __func__ << ", m_count=" << m_count << " - " << strDate() << "\n";

        m_count += 1;
        m_timer.expires_at( m_timer.expires_at() + boost::posix_time::seconds(1) );
        m_timer.async_wait(boost::bind(&MyClass::print, this));
        //m_timer.async_wait(boost::bind(&My
    }
Пример #20
0
inline void wamp_dealer_invocation::set_timeout(timeout_callback callback, unsigned timeout_ms)
{
    // Do not allow setting a timeout value of 0 as this is a
    // special timeout value indicating infinite timeout. So
    // insted we just don't arm the timer which gives us an
    // infinite timeout.
    if (timeout_ms) {
        m_timeout_timer.expires_from_now(boost::posix_time::milliseconds(timeout_ms));
        m_timeout_timer.async_wait(callback);
    }
}
Пример #21
0
void AsyncLoopTimer(boost::function<TaskState()> doWork, boost::asio::deadline_timer& dTimer, int millisecs)
{
    TaskState st = doWork();

    if (st == TASK_WORKING)
    {
        dTimer.expires_from_now(boost::posix_time::milliseconds(millisecs));
        dTimer.async_wait(boost::bind(AsyncLoopTimer, doWork, boost::ref(dTimer), millisecs));
    }

    // Work is over; nothing to do, as the timer is not rearmed
}
Пример #22
0
void RealSettings::queueSave()
{
    LogSpam << "RealSettings::queueSave(" << name_ << ")";
    grab aholdof(lock_);
    if (!saveQueued_)
    {
        saveQueued_ = true;
        //  possibly aggregate multiple updates into a single write
        saveTimer_.expires_from_now(boost::posix_time::seconds(10));
        saveTimer_.async_wait(boost::bind(&RealSettings::save, this, shared_from_this()));
    }
}
Пример #23
0
int main(int argc, char** argv)
{
	po::options_description desc("Options");
	
	desc.add_options()
		("port,p", po::value<int>(), "Port")
		("fifo_size,F", po::value<int>(), "FIFO size")
		("fifo_low_watermark,L", po::value<unsigned int>(), "FIFO low watermark")
		("fifo_high_watermark,H", po::value<unsigned int>(), "FIFO high watermark")
		("buf_len,X", po::value<unsigned int>(), "Buffer length")
		("tx_interval,i", po::value<int>(), "Mixer call interval");
	
	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
	
	if (vm.count("port"))
		port = vm["port"].as<int>();
	if (vm.count("fifo_size"))
		fifo_size = vm["fifo_size"].as<int>();
		
	fifo_high = fifo_size;
		
	if (vm.count("fifo_low_watermark"))
		fifo_low = vm["fifo_low_watermark"].as<unsigned int>();
	if (vm.count("fifo_high_watermark"))
		fifo_high = vm["fifo_high_watermark"].as<unsigned int>();
	if (vm.count("buf_len"))
		buf_len = vm["buf_len"].as<unsigned int>();
	if (vm.count("tx_interval"))
		tx_interval = vm["tx_interval"].as<int>();
	
	tcp_endpoint = tcp::endpoint(tcp::v6(), port);
	udp_endpoint = udp::endpoint(udp::v6(), port);
	acceptor = tcp::acceptor(io_service, tcp_endpoint);
	udp_socket = udp::socket(io_service, udp_endpoint);
	
	tcp_socket = new tcp::socket(io_service);
	
	acceptor.listen();
	acceptor.async_accept(*tcp_socket, receive_connection);
	udp_socket.async_receive_from(ba::buffer(buffer), client_udp_endpoint, read_udp_data);
	connection_timer.async_wait(check_connections);
	report_timer.async_wait(generate_report);
	
	signals.async_wait(signal_received);
	
	broadcast_timer.expires_from_now(boost::posix_time::milliseconds(tx_interval));
	broadcast_timer.async_wait(broadcast_data);
	
	io_service.run();
}
Пример #24
0
 JoystickDroneHandler(Drone& drone, Joystick& joystick)
 : drone_(drone),
   joystick_(joystick),
   deadline_(drone.io_service()),
   heigthAdj_(0.0),
   yawAdj_(0.0)  
 {
   joystick.setButtonHandler(boost::bind(&JoystickDroneHandler::handleButton, this, _1, _2));
   joystick.setAxisHandler(boost::bind(&JoystickDroneHandler::handleAxis, this, _1, _2));
   joystick.start();
   deadline_.async_wait(boost::bind(&JoystickDroneHandler::checkDeadLine, this));
   deadline_.expires_from_now(boost::posix_time::milliseconds(50));
 }
Пример #25
0
 void checkDeadLine()
 {
   if (deadline_.expires_at() <= boost::asio::deadline_timer::traits_type::now())
   {
     if (yawAdj_ != 0.0 || heigthAdj_ != 0.0) {
       drone_.Yaw(drone_.Yaw() + yawAdj_);
       drone_.H(drone_.H() + heigthAdj_);
       drone_.SendCmd();
     }
     deadline_.expires_from_now(boost::posix_time::milliseconds(50));
   }
   deadline_.async_wait(boost::bind(&JoystickDroneHandler::checkDeadLine, this));
 }
Пример #26
0
void SenderImpl::start(Sender_weak weak)
{
    Sender_ptr ptr (weak.lock());

    if (!ptr)
        return;

    m_evaluator.evaluate(m_config->code());

    bool hasErr = m_evaluator.hasError();

    if (!hasErr)
    {
        OperationDescriptor_ptr op = m_config->operation();

        // Clone the original request
        // We can't modify an emited request
        Holder srcHolder = op->get_holder(m_config->request());

        m_request = op->create_request();
        Holder dstHolder = op->get_holder(m_request);

        op->copy(srcHolder, dstHolder);

        // m_request is the working request
        m_evaluator.init(m_request);

        hasErr = m_evaluator.hasError();
    }

    if (!hasErr)
    {
        m_timer.expires_from_now(
                boost::posix_time::milliseconds(
                    m_config->initDelay()));

        m_timer.async_wait(
                boost::bind(&SenderImpl::handleTimeout,
                    this, weak, _1));
    }
    else
    {
        m_config->notifyFinished();

        emit finished(m_config);

        emit error(m_evaluator.error());
    }
}
Пример #27
0
	/// Set / reset the timeout timer
	void setTimeout( unsigned timeout )
	{
		if ( timeout == 0 )	{
			LOG_TRACE << "Timeout for connection to " << identifier() << " reset";
			m_timer.cancel();
		}
		else	{
			m_timer.cancel();
			m_timer.expires_from_now( boost::posix_time::seconds( timeout ));
			m_timer.async_wait( m_strand.wrap( boost::bind( &ConnectionBase::handleTimeout,
									this->shared_from_this(),
									boost::asio::placeholders::error )));
			LOG_TRACE << "Timeout for connection to " << identifier() << " set to " << timeout << "s";
		}
	}
Пример #28
0
    void timer_cb(const boost::system::error_code &ec) {

        if (!ec) {
            write(ws::message::opcode::binary,
                  boost::asio::buffer(&angle_, sizeof (angle_)), [this]()
            {
                auto self(shared_from_this());
                small_change();
                timer_.expires_from_now(boost::posix_time::milliseconds(100));
                timer_.async_wait([this, self](const boost::system::error_code &ec) {
                    timer_cb(ec);
                });
            });
        }
    }
Пример #29
0
void thread_pool_checker::on_check(const boost::system::error_code& error)
{
    // On error, return early.
    if (error)
        return;

    // Check how long this job was waiting in the service queue.  This
    // returns the expiration time relative to now.  Thus, if it expired
    // 7 seconds ago, then the delta time is -7 seconds.
    boost::posix_time::time_duration delta = timer_.expires_from_now();
    long wait_in_seconds = -delta.seconds();

    // If the time delta is greater than the threshold, then the job
    // remained in the service queue for too long, so increase the
    // thread pool.
    std::cout << "Job job sat in queue for " << wait_in_seconds << " seconds."
                << std::endl;
    if (threshold_seconds_ < wait_in_seconds)
    {
        std::cout << "Increasing thread pool." << std::endl;
        threads_.create_thread(
                    boost::bind(&boost::asio::io_service::run, &io_service_));
    }

    // Otherwise, schedule another pool check.
    run();
}
Пример #30
0
    TimerHandler(Network::IOService *io, SentMessage *messageInfo, const Duration& num_seconds)
        : mTimer(*static_cast<boost::asio::io_service*>(io), boost::posix_time::microseconds(num_seconds.toMicroseconds())) {

        mSentMessage = messageInfo;
        mTimer.async_wait(
            boost::bind(&TimerHandler::timedOut, this, boost::asio::placeholders::error));
    }