Shutdown messages and sigint handling.

This commit is contained in:
Ian Gulliver
2015-02-07 16:18:07 -08:00
parent 6fc6070d5f
commit 0e0a3eab8b
4 changed files with 23 additions and 0 deletions

View File

@@ -218,6 +218,9 @@ void CryptoPubConnBase::OnReadable() {
CryptoPubServer::CryptoPubServer(const std::string& secret_key)
: secret_key_(secret_key),
event_base_(event_base_new()) {
auto signal_event = evsignal_new(event_base_, SIGINT, &CryptoPubServer::Shutdown_, this);
event_add(signal_event, NULL);
assert(secret_key_.length() == crypto_box_SECRETKEYBYTES);
struct sockaddr_in6 server_addr = {0};
@@ -258,6 +261,15 @@ void CryptoPubServer::Loop() {
event_base_dispatch(event_base_);
}
void CryptoPubServer::Shutdown_(evutil_socket_t sig, short events, void *this__) {
auto this_ = (CryptoPubServer*)this__;
this_->Shutdown();
}
void CryptoPubServer::Shutdown() {
event_base_loopexit(event_base_, NULL);
}
CryptoPubServerConnection::CryptoPubServerConnection(struct bufferevent* bev, const std::string& secret_key)
: CryptoPubConnBase(secret_key) {