mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 23:14:20 +08:00
added SIGINT and SIGTERM handling to unix client and server.
either signal causes the main thread to be cancelled. added necessary code to make main thread cancellation clean up nicely.
This commit is contained in:
@@ -7,18 +7,19 @@
|
||||
#include "IPrimaryScreen.h"
|
||||
#include "ISocketFactory.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "XSynergy.h"
|
||||
#include "CNetworkAddress.h"
|
||||
#include "ISocket.h"
|
||||
#include "IListenSocket.h"
|
||||
#include "XSocket.h"
|
||||
#include "CLock.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include "CTimerThread.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "CFunctionJob.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "CLog.h"
|
||||
#include "XSocket.h"
|
||||
#include "XSynergy.h"
|
||||
#include "XThread.h"
|
||||
#include <assert.h>
|
||||
#include <memory>
|
||||
|
||||
@@ -92,15 +93,26 @@ void CServer::run()
|
||||
log((CLOG_ERR "server error: %s", e.what()));
|
||||
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping server"));
|
||||
delete m_httpServer;
|
||||
m_httpServer = NULL;
|
||||
cleanupThreads();
|
||||
closePrimaryScreen();
|
||||
}
|
||||
catch (XThread&) {
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping server"));
|
||||
delete m_httpServer;
|
||||
m_httpServer = NULL;
|
||||
cleanupThreads();
|
||||
closePrimaryScreen();
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
log((CLOG_DEBUG "unknown server error"));
|
||||
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping server"));
|
||||
delete m_httpServer;
|
||||
m_httpServer = NULL;
|
||||
cleanupThreads();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "CMutex.h"
|
||||
#include "CNetwork.h"
|
||||
#include "CThread.h"
|
||||
#include "XThread.h"
|
||||
#include "stdfstream.h"
|
||||
#include <assert.h>
|
||||
|
||||
@@ -47,11 +48,12 @@ void realMain()
|
||||
s_logMutex = &logMutex;
|
||||
CLog::setLock(&logLock);
|
||||
|
||||
// initialize network library
|
||||
CNetwork::init();
|
||||
|
||||
CServer* server = NULL;
|
||||
try {
|
||||
// initialize network library
|
||||
CNetwork::init();
|
||||
|
||||
// load configuration
|
||||
CConfig config;
|
||||
{
|
||||
log((CLOG_DEBUG "opening configuration"));
|
||||
@@ -63,9 +65,12 @@ void realMain()
|
||||
log((CLOG_DEBUG "configuration read successfully"));
|
||||
}
|
||||
|
||||
// run server
|
||||
server = new CServer();
|
||||
server->setConfig(config);
|
||||
server->run();
|
||||
|
||||
// clean up
|
||||
delete server;
|
||||
CNetwork::cleanup();
|
||||
CLog::setLock(NULL);
|
||||
@@ -110,6 +115,10 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
MessageBox(NULL, msg.c_str(), "error", MB_OK | MB_ICONERROR);
|
||||
return 1;
|
||||
}
|
||||
catch (XThread&) {
|
||||
// terminated
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -132,6 +141,10 @@ int main(int argc, char** argv)
|
||||
fprintf(stderr, "failed: %s\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
catch (XThread&) {
|
||||
// terminated
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user