mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-07 20:34:28 +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:
@@ -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