Shutdown messages and sigint handling.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
@@ -52,4 +54,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
auto client = CryptoPubClient::FromHostname(server_address, server_port, secret_key, server_public_key, channel_bitrates);
|
auto client = CryptoPubClient::FromHostname(server_address, server_port, secret_key, server_public_key, channel_bitrates);
|
||||||
client->Loop();
|
client->Loop();
|
||||||
|
|
||||||
|
std::cerr << "Shutting down" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
@@ -24,4 +26,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
CryptoPubServer server(secret_key);
|
CryptoPubServer server(secret_key);
|
||||||
server.Loop();
|
server.Loop();
|
||||||
|
|
||||||
|
std::cerr << "Shutting down" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
12
crypto.cc
12
crypto.cc
@@ -218,6 +218,9 @@ void CryptoPubConnBase::OnReadable() {
|
|||||||
CryptoPubServer::CryptoPubServer(const std::string& secret_key)
|
CryptoPubServer::CryptoPubServer(const std::string& secret_key)
|
||||||
: secret_key_(secret_key),
|
: secret_key_(secret_key),
|
||||||
event_base_(event_base_new()) {
|
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);
|
assert(secret_key_.length() == crypto_box_SECRETKEYBYTES);
|
||||||
|
|
||||||
struct sockaddr_in6 server_addr = {0};
|
struct sockaddr_in6 server_addr = {0};
|
||||||
@@ -258,6 +261,15 @@ void CryptoPubServer::Loop() {
|
|||||||
event_base_dispatch(event_base_);
|
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)
|
CryptoPubServerConnection::CryptoPubServerConnection(struct bufferevent* bev, const std::string& secret_key)
|
||||||
: CryptoPubConnBase(secret_key) {
|
: CryptoPubConnBase(secret_key) {
|
||||||
|
|||||||
3
crypto.h
3
crypto.h
@@ -61,8 +61,11 @@ class CryptoPubServer : public CryptoBase {
|
|||||||
CryptoPubServer(const std::string& secret_key);
|
CryptoPubServer(const std::string& secret_key);
|
||||||
~CryptoPubServer();
|
~CryptoPubServer();
|
||||||
void Loop();
|
void Loop();
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void Shutdown_(evutil_socket_t sig, short events, void *this__);
|
||||||
|
|
||||||
static void OnNewConn_(struct evconnlistener* listener, int fd, struct sockaddr* client_addr, int client_addrlen, void* this__);
|
static void OnNewConn_(struct evconnlistener* listener, int fd, struct sockaddr* client_addr, int client_addrlen, void* this__);
|
||||||
void OnNewConn(int fd, struct sockaddr* client_addr, int client_addrlen);
|
void OnNewConn(int fd, struct sockaddr* client_addr, int client_addrlen);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user