예제 #1
0
 void do_signal(const boost::system::error_code&,
                int signal_number)
 {
   if (signal_number == SIGHUP) {
     callback();
     signals.async_wait(boost::bind(&handlers::do_signal, this, _1, _2));
   } else
     signals.get_io_service().stop();
 }
예제 #2
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));
 }
예제 #3
0
	application(boost::asio::io_service & io_service, short port)
		: io_service_(io_service)
		, echo_service_(io_service_)
		, signals_(io_service_, SIGTERM, SIGINT)
		, server_(io_service_, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
		, motd_timer_(io_service_)
	{
		echo_service_.start();
		signals_.async_wait(boost::bind(&application::operator(), this, boost::asio::placeholders::error(), _2));
		start_motd_timer();
	}
예제 #4
0
파일: main.cpp 프로젝트: murzz/stuff
   thread_pool(std::size_t pool_size) :
   work_(io_service_), signals_(io_service_, SIGINT, SIGTERM)
   {
      DLOG(INFO)<< __func__;

      for (std::size_t idx = 0; idx < pool_size; ++idx)
      {
         threads_.create_thread( boost::bind(&boost::asio::io_service::run, boost::ref(io_service_)));
      }

      signals_.async_wait( boost::bind(&boost::asio::io_service::stop, &io_service_));
   }
예제 #5
0
 // private
 void handle_signals(
         const boost::system::error_code& error,
         int signal_number)
 {
     if (error) {
         std::cerr << "Error in signal handling: " << error << '\n';
     } else {
         // If signals occures while there is no waiting handlers,
         // signal notification is queued, so it won't be missed
         // while we running users_signal_handler_
         detail::make_task_wrapped(boost::bind(
             boost::ref(users_signal_handler_), signal_number
         ))(); // make and run task_wrapped
     }
     
     signals_.async_wait(boost::bind(
         &tasks_processor::handle_signals, this, _1, _2
     ));
 }
예제 #6
0
    void register_signals_handler(
            const Func& f,
            const std::vector<int>& signals_to_wait)
    {
        // Making shure that this is the first call
        assert(!users_signal_handler_); 

        users_signal_handler_ = f;
        std::for_each(
            signals_to_wait.begin(),
            signals_to_wait.end(),
            boost::bind(
                &boost::asio::signal_set::add, &signals_, _1
            )
        );

        signals_.async_wait(boost::bind(
            &tasks_processor::handle_signals, this, _1, _2
        ));
    }