Created
May 2, 2018 14:26
-
-
Save xueliu/11122f1b2c609c1ee98fbe633798d540 to your computer and use it in GitHub Desktop.
using std::function to provide signal handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
#include <iostream> | |
namespace { | |
std::function<void(int)> shutdown_handler; | |
void signal_handler(int signal) { shutdown_handler(signal); } | |
} // namespace | |
int main(int argc, char *argv[]) { | |
std::signal(SIGINT, signal_handler); | |
MyTCPServer server; | |
shutdown_handler = [&](int signal) { | |
std::cout << "Server shutdown...\n"; | |
server.shutdown(); | |
}; | |
server.do_work_for_ever(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment