From 8d7d5225c482bfd52e0cea7399be2f4d00c64a92 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Thu, 21 May 2020 18:52:48 +0100 Subject: [PATCH] #70 Exit client cleanly on signal --- src/client.cpp | 29 ++++++++++++++++++++++++++++- src/client.h | 6 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/client.cpp b/src/client.cpp index 99f4f588..291100bd 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -79,7 +79,8 @@ CClient::CClient ( const quint16 iPortNumber, bJitterBufferOK ( true ), strCentralServerAddress ( "" ), eCentralServerAddressType ( AT_DEFAULT ), - iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ) + iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ), + pSignalHandler ( CSignalHandler::getSingletonP() ) { int iOpusError; @@ -213,6 +214,10 @@ CClient::CClient ( const quint16 iPortNumber, QObject::connect ( &Socket, SIGNAL ( InvalidPacketReceived ( CHostAddress ) ), this, SLOT ( OnInvalidPacketReceived ( CHostAddress ) ) ); + QObject::connect ( pSignalHandler, + SIGNAL ( HandledSignal ( int ) ), + this, SLOT ( OnHandledSignal ( int ) ) ); + // start the socket (it is important to start the socket after all // initializations and connections) @@ -656,6 +661,28 @@ void CClient::OnCLChannelLevelListReceived ( CHostAddress InetAddr, emit CLChannelLevelListReceived ( InetAddr, vecLevelList ); } +void CClient::OnHandledSignal(int sigNum) +{ +#ifdef _WIN32 + // Windows does not actually get OnHandledSignal triggered + QCoreApplication::instance()->exit(); + Q_UNUSED ( sigNum ) +#else + switch ( sigNum ) + { + + case SIGINT: + case SIGTERM: + // This should trigger OnAboutToQuit + QCoreApplication::instance()->exit(); + break; + + default: + break; + } +#endif +} + void CClient::Start() { // init object diff --git a/src/client.h b/src/client.h index 743a9ff4..e97af2ee 100755 --- a/src/client.h +++ b/src/client.h @@ -39,6 +39,7 @@ #include "channel.h" #include "util.h" #include "buffer.h" +#include "signalhandler.h" #ifdef LLCON_VST_PLUGIN # include "vstsound.h" #else @@ -389,6 +390,8 @@ protected: // for ping measurement CPreciseTime PreciseTime; + CSignalHandler* pSignalHandler; + public slots: void OnSendProtMessage ( CVector vecMessage ); void OnInvalidPacketReceived ( CHostAddress RecHostAddr ); @@ -417,6 +420,9 @@ public slots: void OnCLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); +private slots: + void OnHandledSignal ( int sigNum ); + signals: void ConClientListMesReceived ( CVector vecChanInfo ); void ChatTextReceived ( QString strChatText );