#70 Exit client cleanly on signal

This commit is contained in:
Peter L Jones 2020-05-21 18:52:48 +01:00
parent 3427c9d260
commit 8d7d5225c4
2 changed files with 34 additions and 1 deletions

View file

@ -79,7 +79,8 @@ CClient::CClient ( const quint16 iPortNumber,
bJitterBufferOK ( true ), bJitterBufferOK ( true ),
strCentralServerAddress ( "" ), strCentralServerAddress ( "" ),
eCentralServerAddressType ( AT_DEFAULT ), eCentralServerAddressType ( AT_DEFAULT ),
iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ) iServerSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ),
pSignalHandler ( CSignalHandler::getSingletonP() )
{ {
int iOpusError; int iOpusError;
@ -213,6 +214,10 @@ CClient::CClient ( const quint16 iPortNumber,
QObject::connect ( &Socket, SIGNAL ( InvalidPacketReceived ( CHostAddress ) ), QObject::connect ( &Socket, SIGNAL ( InvalidPacketReceived ( CHostAddress ) ),
this, SLOT ( OnInvalidPacketReceived ( 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 // start the socket (it is important to start the socket after all
// initializations and connections) // initializations and connections)
@ -656,6 +661,28 @@ void CClient::OnCLChannelLevelListReceived ( CHostAddress InetAddr,
emit CLChannelLevelListReceived ( InetAddr, vecLevelList ); 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() void CClient::Start()
{ {
// init object // init object

View file

@ -39,6 +39,7 @@
#include "channel.h" #include "channel.h"
#include "util.h" #include "util.h"
#include "buffer.h" #include "buffer.h"
#include "signalhandler.h"
#ifdef LLCON_VST_PLUGIN #ifdef LLCON_VST_PLUGIN
# include "vstsound.h" # include "vstsound.h"
#else #else
@ -389,6 +390,8 @@ protected:
// for ping measurement // for ping measurement
CPreciseTime PreciseTime; CPreciseTime PreciseTime;
CSignalHandler* pSignalHandler;
public slots: public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage ); void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnInvalidPacketReceived ( CHostAddress RecHostAddr ); void OnInvalidPacketReceived ( CHostAddress RecHostAddr );
@ -417,6 +420,9 @@ public slots:
void OnCLChannelLevelListReceived ( CHostAddress InetAddr, void OnCLChannelLevelListReceived ( CHostAddress InetAddr,
CVector<uint16_t> vecLevelList ); CVector<uint16_t> vecLevelList );
private slots:
void OnHandledSignal ( int sigNum );
signals: signals:
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo ); void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
void ChatTextReceived ( QString strChatText ); void ChatTextReceived ( QString strChatText );