mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-30 15:56:00 +08:00
cleaned up some minor bugs.
This commit is contained in:
@@ -52,25 +52,36 @@ CClient::camp(bool on)
|
||||
m_camp = on;
|
||||
}
|
||||
|
||||
bool
|
||||
CClient::open()
|
||||
{
|
||||
// open the screen
|
||||
try {
|
||||
log((CLOG_INFO "opening screen"));
|
||||
openSecondaryScreen();
|
||||
return true;
|
||||
}
|
||||
catch (XScreenOpenFailure&) {
|
||||
// can't open screen yet. wait a few seconds to retry.
|
||||
CThread::sleep(3.0);
|
||||
log((CLOG_INFO "failed to open screen"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CClient::run(const CNetworkAddress& serverAddress)
|
||||
{
|
||||
// check preconditions
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
assert(m_screen != NULL);
|
||||
}
|
||||
|
||||
CThread* thread = NULL;
|
||||
try {
|
||||
log((CLOG_NOTE "starting client"));
|
||||
|
||||
// connect to secondary screen
|
||||
while (m_screen == NULL) {
|
||||
try {
|
||||
openSecondaryScreen();
|
||||
}
|
||||
catch (XScreenOpenFailure&) {
|
||||
// can't open screen yet. wait a few seconds to retry.
|
||||
log((CLOG_INFO "failed to open screen. waiting to retry."));
|
||||
CThread::sleep(3.0);
|
||||
}
|
||||
}
|
||||
|
||||
// start server interactions
|
||||
m_serverAddress = &serverAddress;
|
||||
thread = new CThread(new TMethodJob<CClient>(this, &CClient::runSession));
|
||||
@@ -108,9 +119,7 @@ CClient::run(const CNetworkAddress& serverAddress)
|
||||
thread->wait();
|
||||
delete thread;
|
||||
}
|
||||
if (m_screen != NULL) {
|
||||
closeSecondaryScreen();
|
||||
}
|
||||
closeSecondaryScreen();
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -123,9 +132,7 @@ CClient::run(const CNetworkAddress& serverAddress)
|
||||
thread->wait();
|
||||
delete thread;
|
||||
}
|
||||
if (m_screen != NULL) {
|
||||
closeSecondaryScreen();
|
||||
}
|
||||
closeSecondaryScreen();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,17 @@ public:
|
||||
// not call this while in run().
|
||||
void camp(bool on);
|
||||
|
||||
// open the client's screen
|
||||
bool open();
|
||||
|
||||
// start the client. does not return until quit() is called.
|
||||
// returns true if the client ever connected to the server
|
||||
// successfully. may also throw exceptions after successfully
|
||||
// connecting.
|
||||
// connecting. a successful open() must preceed this call.
|
||||
bool run(const CNetworkAddress& serverAddress);
|
||||
|
||||
// tell client to exit gracefully
|
||||
// tell client to exit run() gracefully. this must only be called
|
||||
// after a successful open().
|
||||
void quit();
|
||||
|
||||
// handle events on client's screen
|
||||
|
||||
@@ -76,6 +76,7 @@ CXWindowsSecondaryScreen::run()
|
||||
void
|
||||
CXWindowsSecondaryScreen::stop()
|
||||
{
|
||||
CDisplayLock display(this);
|
||||
doStop();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,11 @@ realMain(CMutex* mutex)
|
||||
// create client
|
||||
s_client = new CClient(s_name);
|
||||
s_client->camp(s_camp);
|
||||
if (!s_client->open()) {
|
||||
delete s_client;
|
||||
s_client = NULL;
|
||||
return 16;
|
||||
}
|
||||
|
||||
// run client
|
||||
if (mutex != NULL) {
|
||||
@@ -96,7 +101,6 @@ realMain(CMutex* mutex)
|
||||
// clean up
|
||||
delete s_client;
|
||||
s_client = NULL;
|
||||
CNetwork::cleanup();
|
||||
CLog::setLock(NULL);
|
||||
s_logMutex = NULL;
|
||||
|
||||
@@ -109,7 +113,6 @@ realMain(CMutex* mutex)
|
||||
}
|
||||
delete s_client;
|
||||
s_client = NULL;
|
||||
CNetwork::cleanup();
|
||||
CLog::setLock(NULL);
|
||||
s_logMutex = NULL;
|
||||
throw;
|
||||
@@ -602,6 +605,8 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
result = restartableMain();
|
||||
}
|
||||
|
||||
CNetwork::cleanup();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -641,6 +646,8 @@ main(int argc, char** argv)
|
||||
result = restartableMain();
|
||||
}
|
||||
|
||||
CNetwork::cleanup();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user