From e37e25567e842dd26273853bdb3671f55bb725e7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 11 Feb 2019 15:07:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E9=98=9F?= =?UTF-8?q?=E5=88=97=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpp/msgqueue.cc | 9 +++++++++ test/app.cc | 15 ++++++++++++++- test/app.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cpp/msgqueue.cc b/cpp/msgqueue.cc index 7ab5660..480cb63 100644 --- a/cpp/msgqueue.cc +++ b/cpp/msgqueue.cc @@ -19,6 +19,15 @@ namespace f8 int curr_im_msgid = 10000; std::map msg_handlers; + ~MsgQueueImp() + { + for (auto& pair : msg_handlers) { + while (!list_empty(&pair.second)) { + MsgQueue::Instance()->RemoveCallBack(pair.second.next); + } + } + } + void ProcessMsg(int msgid, const a8::XParams& param) { auto itr = msg_handlers.find(msgid); diff --git a/test/app.cc b/test/app.cc index 2992f5b..b12a5e1 100644 --- a/test/app.cc +++ b/test/app.cc @@ -21,12 +21,18 @@ struct IMMsgNode unsigned short msgid; a8::XParams params; IMMsgNode* next = nullptr; - }; const char* const PROJ_LOG_ROOT = "/data/logs/%s/logs"; const char* const PROJ_LOG_FILENAME = "log_$pid_%Y%m%d.log"; +static void StopApp(int signo) +{ + printf("Stop App...\n"); + App::Instance()->UnInit(); + exit(0); +} + void App::Init(int argc, char* argv[]) { this->argc = argc; @@ -52,6 +58,8 @@ void App::Init(int argc, char* argv[]) f8::DBPool::Instance()->SetThreadNum(10); a8::UdpLog::Instance()->Info("f8test starting instance_id:%d pid:%d", {instance_id, getpid()}); + + signal(SIGINT, StopApp); } void App::UnInit() @@ -72,6 +80,11 @@ void App::UnInit() loop_mutex_ = nullptr; } +void App::Terminate() +{ + terminated = true; +} + int App::Run() { if (terminated) { diff --git a/test/app.h b/test/app.h index df1651a..c4a918d 100644 --- a/test/app.h +++ b/test/app.h @@ -13,6 +13,7 @@ class App : public a8::Singleton void Init(int argc, char* argv[]); void UnInit(); + void Terminate(); int Run();