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() ) );
QObject::connect ( pSignalHandler,
SIGNAL ( ShutdownSignal ( int ) ),
this, SLOT ( OnShutdown ( int ) ) );
SIGNAL ( HandledSignal ( int ) ),
this, SLOT ( OnHandledSignal ( int ) ) );
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();
Q_UNUSED ( sigNum )
#else
switch ( sigNum )
{
case SIGINT:
case SIGTERM:
// This should trigger OnAboutToQuit
QCoreApplication::instance()->exit();
break;
default:
break;
}
#endif
}
void CServer::Start()

View file

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

View file

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