mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-09 07:22:21 +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:
@@ -6,11 +6,12 @@
|
||||
#include "ISecondaryScreen.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "CLock.h"
|
||||
#include "CLog.h"
|
||||
#include "CThread.h"
|
||||
#include "CTimerThread.h"
|
||||
#include "XSynergy.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "CLog.h"
|
||||
#include "XSynergy.h"
|
||||
#include "XThread.h"
|
||||
#include <assert.h>
|
||||
#include <memory>
|
||||
|
||||
@@ -71,6 +72,7 @@ void CClient::run(const CNetworkAddress& serverAddress)
|
||||
log((CLOG_ERR "client error: %s", e.what()));
|
||||
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping client"));
|
||||
if (thread != NULL) {
|
||||
thread->cancel();
|
||||
thread->wait();
|
||||
@@ -78,10 +80,22 @@ void CClient::run(const CNetworkAddress& serverAddress)
|
||||
}
|
||||
closeSecondaryScreen();
|
||||
}
|
||||
catch (XThread&) {
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping client"));
|
||||
if (thread != NULL) {
|
||||
thread->cancel();
|
||||
thread->wait();
|
||||
delete thread;
|
||||
}
|
||||
closeSecondaryScreen();
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
log((CLOG_DEBUG "unknown client error"));
|
||||
|
||||
// clean up
|
||||
log((CLOG_NOTE "stopping client"));
|
||||
if (thread != NULL) {
|
||||
thread->cancel();
|
||||
thread->wait();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user