|
Boost Users : |
Subject: Re: [Boost-users] boost asio daemon
From: Marat Abrarov (abrarov_at_[hidden])
Date: 2013-04-16 13:29:40
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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net