singal handler bug fix

This commit is contained in:
infactum 2019-02-08 18:29:45 +05:00
parent fa9798eff1
commit b76fd4bf41
3 changed files with 8 additions and 8 deletions

View File

@ -23,6 +23,8 @@ namespace td_api = td::td_api;
#define CALL_PROTO_MIN_LAYER 65
volatile sig_atomic_t e_flag = 0;
namespace state_machine::guards {
bool IsIncoming::operator()(const td::td_api::object_ptr<td::td_api::updateCall> &event) const {
return !event->call_->is_outgoing_;
@ -709,10 +711,13 @@ Gateway::Gateway(sip::Client &sip_client_, tg::Client &tg_client_,
: sip_client_(sip_client_), tg_client_(tg_client_), logger_(std::move(logger_)),
sip_events_(sip_events_), tg_events_(tg_events_), settings_(settings) {}
void Gateway::start(volatile sig_atomic_t e_flag) {
void Gateway::start() {
load_cache();
signal(SIGINT, [](int) { e_flag = 1; });
signal(SIGTERM, [](int) { e_flag = 1; });
while (!e_flag) {
auto tick_start = std::chrono::steady_clock::now();

View File

@ -270,7 +270,7 @@ public:
Gateway &operator=(const Gateway &) = delete;
void start(volatile sig_atomic_t e_flag);
void start();
private:
std::shared_ptr<spdlog::logger> logger_;

View File

@ -26,8 +26,6 @@
#include "sip.h"
#include "gateway.h"
volatile sig_atomic_t e_flag = 0;
int main() {
pthread_setname_np(pthread_self(), "main");
@ -80,10 +78,7 @@ int main() {
auto gateway = std::make_unique<Gateway>(*sip_client, *tg_client, sip_events, tg_events, logger, settings);
signal(SIGINT, [](int) { e_flag = 1; });
signal(SIGTERM, [](int) { e_flag = 1; });
gateway->start(e_flag);
gateway->start();
logger->info("performing a graceful shutdown...");
spdlog::drop_all();