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:
crs
2002-06-02 18:49:35 +00:00
parent 1da9be88c9
commit 1d3807cb0e
7 changed files with 115 additions and 25 deletions

View File

@@ -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