Control-C olayını nasıl ele alırım veya boost :: asio sunucumu nasıl durdurabilirim. Bir tcp & udp birleşik sunucum var ve ctrl-c'ye bastığımda temiz bir şekilde çıkabilmek istiyorum. İşlenmemiş kontrol için ilk fırsat istisnası-C. Burada sigint (Ctrl-C) için bir sinyal işleyici kaydedebilirsiniz hangi ile benim kodBir boost tcp/udp sunucusunda control-c'nin nasıl işleneceği
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;
}
olası yinelenen gibi, asio gelen signal_set kullanabilirsiniz ] (http://stackoverflow.com/questions/4639909/standard-way-to-perform-a-clean-shutdown-with-boost-asio) – CharlesB