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 #define CALL_PROTO_MIN_LAYER 65
volatile sig_atomic_t e_flag = 0;
namespace state_machine::guards { namespace state_machine::guards {
bool IsIncoming::operator()(const td::td_api::object_ptr<td::td_api::updateCall> &event) const { bool IsIncoming::operator()(const td::td_api::object_ptr<td::td_api::updateCall> &event) const {
return !event->call_->is_outgoing_; 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_client_(sip_client_), tg_client_(tg_client_), logger_(std::move(logger_)),
sip_events_(sip_events_), tg_events_(tg_events_), settings_(settings) {} sip_events_(sip_events_), tg_events_(tg_events_), settings_(settings) {}
void Gateway::start(volatile sig_atomic_t e_flag) { void Gateway::start() {
load_cache(); load_cache();
signal(SIGINT, [](int) { e_flag = 1; });
signal(SIGTERM, [](int) { e_flag = 1; });
while (!e_flag) { while (!e_flag) {
auto tick_start = std::chrono::steady_clock::now(); auto tick_start = std::chrono::steady_clock::now();

View File

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

View File

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