boost signal handling

Hi,

I am newbie to boost c++ world. For portability sake, I am planning to use boost libraries on signal handling. I want my application to trap all the termination signals sent to the application and convert that into proper application closure. The sample code I use for this is,

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/impl/io_service.hpp>
#include <stdio.h>



void handler(
const boost::system::error_code& error,
int signal_number)
{
if (!error)
{
printf( "Signal received\n" );
// A signal occurred.
}
}


int main()
{
boost::asio::io_service srv;
// Construct a signal set registered for process termination.
boost::asio::signal_set signals(srv, SIGINT, SIGTERM);

// Start an asynchronous wait for one of the signals to occur.
signals.async_wait(handler);

for(;;);
}

When I do ctrl+c from the execution terminal, the handler is not getting called at all ( But the singal is captured ). There should be some issue while assigning the signal handler for the signal. Anybody can help me on this?


Don't take this as correct, because it's only based on a vague memory of something I read months ago, but I think that you need to call io_service.run() (or a similar function) to process asynchronous events.
Topic archived. No new replies allowed.