Ejemplo n.º 1
0
	void timeout(const boost::system::error_code &e) {
		if(
		    mum!=nullptr &&
		    m_audiofifo!=nullptr &&
		    mum->getConnectionState()==mumlib::ConnectionState::CONNECTED &&
		    m_audiofifo->getNoOfFrames() >= output_frame_size
		) {
			timer.expires_from_now(boost::posix_time::milliseconds(60));
			auto packet=m_audiofifo->getAudio();
			mum->sendAudioData(packet->m_samples, output_frame_size, mumlib::SourceAudioPacketType::FLOAT);
			delete packet;
		} else {
			timer.expires_from_now(boost::posix_time::seconds(2));
		}
		timer.async_wait(timeout_handler);
	};
Ejemplo n.º 2
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);
	}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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));
  }
}
Ejemplo n.º 5
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();
}
Ejemplo n.º 6
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) ) );
		}
Ejemplo n.º 7
0
Archivo: main.cpp Proyecto: CCJY/coliru
 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())));
     }
 }
Ejemplo n.º 8
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));
}
Ejemplo n.º 9
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)));
 }
Ejemplo n.º 10
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);
     });
 }
Ejemplo n.º 11
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));
  }
Ejemplo n.º 12
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));
 }
Ejemplo n.º 13
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)));
	}
}
Ejemplo n.º 14
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);
    }
}
Ejemplo n.º 15
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));
 }
Ejemplo n.º 16
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
}
Ejemplo n.º 17
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()));
    }
}
Ejemplo n.º 18
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));
 }
Ejemplo n.º 19
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));
 }
Ejemplo n.º 20
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());
    }
}
Ejemplo n.º 21
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";
		}
	}
Ejemplo n.º 22
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);
                });
            });
        }
    }
Ejemplo n.º 23
0
    void handle_timeout(const boost::system::error_code& ec)
    {
        if (--count_ > 0)
        {
            rc_->stop();
            rc_.reset( new rc_check(timer_.io_service(), std::string(p_.pp.login).append("@").append(p_.pp.domain),
                            p_.pp.ukey, p_.l, 1) );

            timer_.expires_from_now(boost::posix_time::milliseconds(rand_r(&seed_) % 500));
            timer_.async_wait(strand_.wrap(boost::bind(&tormoz_get::handle_timeout, shared_from_this(), _1)));
        }
        else if (rc_)
        {
            rc_->stop();
            rc_.reset();
        }
    }
void cia_server::set_idol_channel_timer()
{
	m_set_idol_channel_timer.expires_from_now(boost::posix_time::milliseconds(m_config_server->get_cti_set_idol_channel_num_elapsed()));
	// BOOST_LOG_SEV(cia_g_logger, AllEvent) << "开始准备定时设置空闲通道数量";
	ptr self = shared_from_this();
	m_set_idol_channel_timer.async_wait([this, self](const error_code& ec){
		if (ec)
		{
			BOOST_LOG_SEV(cia_g_logger, Debug) << "已停止定时设置空闲通道数量";
			return;
		}
		else
		{
			m_config_server->set_idol_channel_number(m_base_voice_card->get_idol_channel_number());
			set_idol_channel_timer();
		}
	});
}
Ejemplo n.º 25
0
 void updateProperty(const Property::ConstPtr &theProperty)
 {
     ViewerApp::updateProperty(theProperty);
     
     // one of our porperties was changed
     if(theProperty == m_texturePath)
     {
         try
         {
             m_textures[0] = gl::createTextureFromFile(*m_texturePath);
             
             if(m_textures[0])
             {
                 // ->CL_INVALID_GL_OBJECT: internal format must be pow2 (RG, RGBA)
                 m_cl_image = cl::ImageGL(m_context, CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0,
                                          m_textures[0].getId());
             }
         }
         catch(cl::Error &error){LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")";}
         catch (FileNotFoundException &e){LOG_WARNING << e.what();}
     }
     else if(theProperty == m_videoPath)
     {
         
     }
     else if(theProperty == m_num_particles)
     {
         scene().removeObject(m_mesh);
         initParticles(*m_num_particles);
     }
     else if(theProperty == m_point_size)
     {
         m_pointMaterial->setPointSize(*m_point_size);
         
         m_timer.cancel();
         m_timer.expires_from_now(boost::posix_time::seconds(2.f));
         m_timer.async_wait(boost::bind(&OpenCLTest::tick, this, _1));
     }
     else if(theProperty == m_point_color)
     {
         m_mesh->material()->setDiffuse(*m_point_color);
     }
 }
Ejemplo n.º 26
0
void thread_pool_checker::schedule_check()
{
    // Thread pool is already at max size.
    if (max_threads_ <= threads_.size())
    {
        std::cout << "Thread pool has reached its max.  Example will shutdown."
                    << std::endl;
        io_service_.stop();
        return;
    }

    // Schedule check to see if pool needs to increase.
    std::cout << "Will check if pool needs to increase in " << periodic_seconds_
                << " seconds." << std::endl;
    timer_.expires_from_now(boost::posix_time::seconds(periodic_seconds_));
    timer_.async_wait(
                boost::bind(&thread_pool_checker::on_check, this,
                            boost::asio::placeholders::error));
}
Ejemplo n.º 27
0
		void AsyncTimer::Action(const boost::system::error_code& _ec, boost::asio::deadline_timer& _t){

			Trace("TRACE AsyncTimer Action");

			if(!_ec){

				builder_.Load();

				_t.expires_from_now(boost::posix_time::seconds(seconds_));

				_t.async_wait(boost::bind(&AsyncTimer::Action, this, boost::asio::placeholders::error, boost::ref(_t)));

			}
			else{
			
				Error("AsyncTimer failed!");
			
			}

		}
Ejemplo n.º 28
0
    /// Handle a diconnect on the underlying connection.
    void disconnected_handler()
    {
      if (connection_->connected())
      {
        connection_->set_connected(false);

        if (disconnected_handler_)
          disconnected_handler_();

        connection_->close();
      }

      // attempt to reconnect in period_ miliseconds
      if (period_ > 0)
      {
        timer_.expires_from_now(boost::posix_time::milliseconds(period_));
        weak_pointer weak_ptr(weak_from_this());
        timer_.async_wait([weak_ptr](boost::system::error_code const& error)
                           { timeout_handler(weak_ptr, error); });
      }
    }
Ejemplo n.º 29
0
 void scheduleNext()
 {
     timer_.expires_from_now(boost::posix_time::seconds(interval_));
     timer_.async_wait(
         boost::bind(&LogRolloverTimer::timerFunc, this, boost::asio::placeholders::error));
 }
Ejemplo n.º 30
0
 void scheduleNext()
 {
     timer_.expires_from_now(boost::posix_time::seconds(10));
     timer_.async_wait(
         boost::bind(&AuditTimer::auditFunc, this, boost::asio::placeholders::error));
 }