Re: [Boost-users] boost asio daemon
Hi, Philipp.
io::io_service l_ioservice; io::signal_set l_signals(l_ioservice, SIGINT, SIGTERM); l_signals.async_wait(daemonhandler); // * l_ioservice.run(); // **
void daemonhandler( const boost::system::Error_code& err ) { if (!err) do some log else do daemon work }
My question is, is the daemonhandler function a function that is called only if the daemon is stopped or that is run during the daemon is active / working?
According to Boost.Asio docs (http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/overview/core/basi cs.html) all callbacks (handlers) are executed (handler::operator() is called) within the threads running asio::io_service::run() (run_one/poll/poll_one). So at the execution point of the daemonhandler function at least one thread of daemon (thread of the daemon's process) runs. If the above code is the only place that executes asio::io_service::run() (see **) then daemonhandler function will be called within the same thread. And if (*) is the only pending async operation then continuation of execution of asio::io_service::run() depends on daemonhandler starting additional async operations on the same instance of asio::io_service (on l_ioservice). Regards, Marat Abrarov.
Am 16.04.2013 um 19:29 schrieb Marat Abrarov:
Hi, Philipp.
io::io_service l_ioservice; io::signal_set l_signals(l_ioservice, SIGINT, SIGTERM); l_signals.async_wait(daemonhandler); // * l_ioservice.run(); // **
void daemonhandler( const boost::system::Error_code& err ) { if (!err) do some log else do daemon work }
My question is, is the daemonhandler function a function that is called only if the daemon is stopped or that is run during the daemon is active / working?
According to Boost.Asio docs (http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/overview/core/basi cs.html) all callbacks (handlers) are executed (handler::operator() is called) within the threads running asio::io_service::run() (run_one/poll/poll_one). So at the execution point of the daemonhandler function at least one thread of daemon (thread of the daemon's process) runs. If the above code is the only place that executes asio::io_service::run() (see **) then daemonhandler function will be called within the same thread. And if (*) is the only pending async operation then continuation of execution of asio::io_service::run() depends on daemonhandler starting additional async operations on the same instance of asio::io_service (on l_ioservice).
Thanks, that's it, thanks for your explanation Phil
participants (2)
-
Marat Abrarov
-
Philipp Kraus