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();
}
Beispiel #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);
	}
Beispiel #3
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())));
     }
 }
Beispiel #4
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);
}
//---------------------------------------------------------
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));
}
Beispiel #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) ) );
		}
Beispiel #7
0
 MyClass(boost::asio::io_service& io) :
     m_timer(io, boost::posix_time::seconds(1)),
     m_count(0)
 {
     m_timer.async_wait(boost::bind(&MyClass::print, this));
     std::cout << "MyClass() - " << strDate() << "\n";
 }
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));
  }
}
 a_timer(boost::asio::io_service &ios, int x, F func):
     f(func), count_max(x), count(0),
     t(ios, boost::posix_time::millisec(500))
 {
     t.async_wait(boost::bind(&a_timer::call_func, this,
                              boost::asio::placeholders::error));
 }
Beispiel #10
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));
    }
Beispiel #11
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)));
 }
Beispiel #12
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_++;
}
Beispiel #13
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));
  }
 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));
 }
Beispiel #15
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);
     });
 }
Beispiel #16
0
int main(int argc, char* argv[]) {


	t.async_wait(&print);

	io.run();

	return EXIT_SUCCESS;
}
 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)));
 }
Beispiel #18
0
	void send(){
		s.async_send(
			boost::asio::buffer(buf),
			s.strand_.wrap(
				boost::bind(&self_type::handle_send, shared_from_this(), _1, _2)));
		timer.async_wait(
			s.strand_.wrap(
				boost::bind(&self_type::handle_time_out, shared_from_this(), _1)));
	}
Beispiel #19
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
        ));

    }
Beispiel #20
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)));
	}
}
Beispiel #21
0
 std::future<int> doit()
 {
   BARK();
   auto cb = [&](const boost::system::error_code&) {
     std::cout << "CB!\n";
     prom.set_value(13);
   };
   dt.async_wait(cb);
   return prom.get_future();
 }
 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));
 }
Beispiel #23
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));
 }
 linux_timer(unsigned int ms, bool repeating, TaskProc proc, void * context)
     : _ms(ms)
     , _repeat(repeating)
     , _timer(crossplat::threadpool::shared_instance().service(), boost::posix_time::milliseconds(ms))
     , _proc(proc)
     , _ctx(context)
     ,_in_callback(false)
     ,_orphan(false)
 {
     _timer.async_wait(boost::bind(&linux_timer::callback, this, boost::asio::placeholders::error));
 }
Beispiel #25
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
    }
Beispiel #26
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));
}
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);
    }
}
Beispiel #28
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()));
    }
}
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
}
Beispiel #30
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));
 }