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

@@ -5,6 +5,7 @@
#include "CNetwork.h"
#include "CNetworkAddress.h"
#include "CThread.h"
#include "XThread.h"
#include <assert.h>
//
@@ -42,20 +43,24 @@ void realMain(const CString& name,
s_logMutex = &logMutex;
CLog::setLock(&logLock);
// initialize network library
CNetwork::init();
CClient* client = NULL;
try {
// initialize network library
CNetwork::init();
// run client
CNetworkAddress addr(hostname, port);
client = new CClient(name);
client->run(addr);
// clean up
delete client;
CNetwork::cleanup();
CLog::setLock(NULL);
s_logMutex = NULL;
}
catch (...) {
// clean up
delete client;
CNetwork::cleanup();
CLog::setLock(NULL);
@@ -93,6 +98,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
@@ -114,6 +123,10 @@ int main(int argc, char** argv)
fprintf(stderr, "failed: %s\n", e.what());
return 1;
}
catch (XThread&) {
// terminated
return 1;
}
}
#endif