How do I handle the control-C event or stop my boost::asio server. I have a tcp & udp combined server and would like to be able to exit cleanly when I press ctrl-c. I get a first chance exception for unhandled control-C. Here is my code
void startTCP()
{
http::syncServer::server serv( 2);
// Set console control handler to allow server to be stopped.
// console_ctrl_function = boost::bind(&http::syncServer::server::stop, &serv);
//SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
// Run the server until stopped.
serv.run();
}
void startUDP()
{
boost::asio::io_service io_service;
http::syncServer::udp_server server(io_service);
// console_ctrl_function = boost::bind(&http::syncServer::udp_server::stop, &server);
// SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
io_service.run();
}
int main(int argc, char* argv[])
{
try
{
boost::shared_ptr<boost::thread> tcpThread( new boost::thread(startTCP));
boost::shared_ptr<boost::thread> udpThread (new boost::thread(startUDP));
/*console_ctrl_function = boost::bind(&http::syncServer::udp_server::stop, &server);
SetConsoleCtrlHandler(console_ctrl_handler, FALSE);*/
tcpThread->join();
udpThread->join();
}
catch (std::exception& e)
{
std::cerr << "exception: " << e.what() << "\n";
}
return 0;
}