Expanded signal handling

This commit is contained in:
Peter L Jones 2020-05-15 20:01:57 +01:00
parent 0928fe4e9f
commit d5c754b580
4 changed files with 33 additions and 10 deletions

View File

@ -471,8 +471,8 @@ CServer::CServer ( const int iNewMaxNumChan,
this, SLOT ( OnAboutToQuit() ) ); this, SLOT ( OnAboutToQuit() ) );
QObject::connect ( pSignalHandler, QObject::connect ( pSignalHandler,
SIGNAL ( ShutdownSignal ( int ) ), SIGNAL ( HandledSignal ( int ) ),
this, SLOT ( OnShutdown ( int ) ) ); this, SLOT ( OnHandledSignal ( int ) ) );
connectChannelSignalsToServerSlots<MAX_NUM_CHANNELS>(); connectChannelSignalsToServerSlots<MAX_NUM_CHANNELS>();
@ -665,10 +665,31 @@ void CServer::OnAboutToQuit()
} }
} }
void CServer::OnShutdown ( int ) void CServer::OnHandledSignal ( int sigNum )
{ {
// This should trigger OnAboutToQuit #ifdef _WIN32
// Windows does not actually get OnHandledSignal triggered
QCoreApplication::instance()->exit(); 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 CServer::Start() void CServer::Start()

View File

@ -441,5 +441,5 @@ public slots:
void OnAboutToQuit(); void OnAboutToQuit();
void OnShutdown ( int ); void OnHandledSignal ( int sigNum );
}; };

View File

@ -75,7 +75,7 @@ CSignalHandler* CSignalHandler::getSingletonP() { return singleton; }
bool CSignalHandler::emitSignal ( int sigNum ) bool CSignalHandler::emitSignal ( int sigNum )
{ {
return QMetaObject::invokeMethod( singleton, "ShutdownSignal", Qt::QueuedConnection, Q_ARG( int, sigNum ) ); return QMetaObject::invokeMethod( singleton, "HandledSignal", Qt::QueuedConnection, Q_ARG( int, sigNum ) );
} }
#ifndef _WIN32 #ifndef _WIN32
@ -124,11 +124,11 @@ QReadWriteLock* CSignalWin::getLock() const
return &lock; return &lock;
} }
BOOL WINAPI CSignalWin::signalHandler ( _In_ DWORD sigNum ) BOOL WINAPI CSignalWin::signalHandler ( _In_ DWORD )
{ {
auto self = getSelf<CSignalWin>(); auto self = getSelf<CSignalWin>();
QReadLocker lock ( self->getLock() ); QReadLocker lock ( self->getLock() );
return self->pSignalHandler->emitSignal ( static_cast<int>( sigNum ) ); return self->pSignalHandler->emitSignal ( -1 );
} }
#else #else
@ -145,12 +145,14 @@ CSignalUnix::CSignalUnix ( CSignalHandler* nPSignalHandler ) :
socketNotifier->setEnabled ( true ); socketNotifier->setEnabled ( true );
setSignalHandled ( SIGUSR1, true );
setSignalHandled ( SIGINT, true ); setSignalHandled ( SIGINT, true );
setSignalHandled ( SIGTERM, true ); setSignalHandled ( SIGTERM, true );
} }
} }
CSignalUnix::~CSignalUnix() { CSignalUnix::~CSignalUnix() {
setSignalHandled ( SIGUSR1, false );
setSignalHandled ( SIGINT, false ); setSignalHandled ( SIGINT, false );
setSignalHandled ( SIGTERM, false ); setSignalHandled ( SIGTERM, false );
} }

View File

@ -104,7 +104,7 @@ public slots:
#endif #endif
signals: signals:
void ShutdownSignal ( int sigNum ); void HandledSignal ( int sigNum );
private: private:
QScopedPointer<CSignalBase> pSignalBase; QScopedPointer<CSignalBase> pSignalBase;
@ -153,7 +153,7 @@ public:
private: private:
mutable QReadWriteLock lock; mutable QReadWriteLock lock;
static BOOL WINAPI signalHandler ( _In_ DWORD sigNum ); static BOOL WINAPI signalHandler ( _In_ DWORD );
}; };
#else #else