cleaned up some minor bugs.
This commit is contained in:
parent
e0f66d162f
commit
ede18cb7f3
|
@ -53,24 +53,35 @@ CClient::camp(bool on)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CClient::run(const CNetworkAddress& serverAddress)
|
CClient::open()
|
||||||
{
|
{
|
||||||
CThread* thread = NULL;
|
// open the screen
|
||||||
try {
|
|
||||||
log((CLOG_NOTE "starting client"));
|
|
||||||
|
|
||||||
// connect to secondary screen
|
|
||||||
while (m_screen == NULL) {
|
|
||||||
try {
|
try {
|
||||||
|
log((CLOG_INFO "opening screen"));
|
||||||
openSecondaryScreen();
|
openSecondaryScreen();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (XScreenOpenFailure&) {
|
catch (XScreenOpenFailure&) {
|
||||||
// can't open screen yet. wait a few seconds to retry.
|
// 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);
|
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"));
|
||||||
|
|
||||||
// start server interactions
|
// start server interactions
|
||||||
m_serverAddress = &serverAddress;
|
m_serverAddress = &serverAddress;
|
||||||
thread = new CThread(new TMethodJob<CClient>(this, &CClient::runSession));
|
thread = new CThread(new TMethodJob<CClient>(this, &CClient::runSession));
|
||||||
|
@ -108,9 +119,7 @@ CClient::run(const CNetworkAddress& serverAddress)
|
||||||
thread->wait();
|
thread->wait();
|
||||||
delete thread;
|
delete thread;
|
||||||
}
|
}
|
||||||
if (m_screen != NULL) {
|
|
||||||
closeSecondaryScreen();
|
closeSecondaryScreen();
|
||||||
}
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
|
@ -123,9 +132,7 @@ CClient::run(const CNetworkAddress& serverAddress)
|
||||||
thread->wait();
|
thread->wait();
|
||||||
delete thread;
|
delete thread;
|
||||||
}
|
}
|
||||||
if (m_screen != NULL) {
|
|
||||||
closeSecondaryScreen();
|
closeSecondaryScreen();
|
||||||
}
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,17 @@ public:
|
||||||
// not call this while in run().
|
// not call this while in run().
|
||||||
void camp(bool on);
|
void camp(bool on);
|
||||||
|
|
||||||
|
// open the client's screen
|
||||||
|
bool open();
|
||||||
|
|
||||||
// start the client. does not return until quit() is called.
|
// start the client. does not return until quit() is called.
|
||||||
// returns true if the client ever connected to the server
|
// returns true if the client ever connected to the server
|
||||||
// successfully. may also throw exceptions after successfully
|
// successfully. may also throw exceptions after successfully
|
||||||
// connecting.
|
// connecting. a successful open() must preceed this call.
|
||||||
bool run(const CNetworkAddress& serverAddress);
|
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();
|
void quit();
|
||||||
|
|
||||||
// handle events on client's screen
|
// handle events on client's screen
|
||||||
|
|
|
@ -76,6 +76,7 @@ CXWindowsSecondaryScreen::run()
|
||||||
void
|
void
|
||||||
CXWindowsSecondaryScreen::stop()
|
CXWindowsSecondaryScreen::stop()
|
||||||
{
|
{
|
||||||
|
CDisplayLock display(this);
|
||||||
doStop();
|
doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,11 @@ realMain(CMutex* mutex)
|
||||||
// create client
|
// create client
|
||||||
s_client = new CClient(s_name);
|
s_client = new CClient(s_name);
|
||||||
s_client->camp(s_camp);
|
s_client->camp(s_camp);
|
||||||
|
if (!s_client->open()) {
|
||||||
|
delete s_client;
|
||||||
|
s_client = NULL;
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
// run client
|
// run client
|
||||||
if (mutex != NULL) {
|
if (mutex != NULL) {
|
||||||
|
@ -96,7 +101,6 @@ realMain(CMutex* mutex)
|
||||||
// clean up
|
// clean up
|
||||||
delete s_client;
|
delete s_client;
|
||||||
s_client = NULL;
|
s_client = NULL;
|
||||||
CNetwork::cleanup();
|
|
||||||
CLog::setLock(NULL);
|
CLog::setLock(NULL);
|
||||||
s_logMutex = NULL;
|
s_logMutex = NULL;
|
||||||
|
|
||||||
|
@ -109,7 +113,6 @@ realMain(CMutex* mutex)
|
||||||
}
|
}
|
||||||
delete s_client;
|
delete s_client;
|
||||||
s_client = NULL;
|
s_client = NULL;
|
||||||
CNetwork::cleanup();
|
|
||||||
CLog::setLock(NULL);
|
CLog::setLock(NULL);
|
||||||
s_logMutex = NULL;
|
s_logMutex = NULL;
|
||||||
throw;
|
throw;
|
||||||
|
@ -602,6 +605,8 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||||
result = restartableMain();
|
result = restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNetwork::cleanup();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,6 +646,8 @@ main(int argc, char** argv)
|
||||||
result = restartableMain();
|
result = restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNetwork::cleanup();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,30 +55,41 @@ CServer::~CServer()
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
CServer::run()
|
CServer::open()
|
||||||
{
|
{
|
||||||
|
// open the screen
|
||||||
try {
|
try {
|
||||||
log((CLOG_NOTE "starting server"));
|
log((CLOG_INFO "opening screen"));
|
||||||
|
|
||||||
// connect to primary screen
|
|
||||||
while (m_primary == NULL) {
|
|
||||||
try {
|
|
||||||
openPrimaryScreen();
|
openPrimaryScreen();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (XScreenOpenFailure&) {
|
catch (XScreenOpenFailure&) {
|
||||||
// can't open screen yet. wait a few seconds to retry.
|
// 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);
|
CThread::sleep(3.0);
|
||||||
|
log((CLOG_INFO "failed to open screen"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch (XUnknownClient& e) {
|
catch (XUnknownClient& e) {
|
||||||
// can't open screen yet. wait a few seconds to retry.
|
// can't open screen yet. wait a few seconds to retry.
|
||||||
|
CThread::sleep(3.0);
|
||||||
log((CLOG_CRIT "unknown screen name `%s'", e.getName().c_str()));
|
log((CLOG_CRIT "unknown screen name `%s'", e.getName().c_str()));
|
||||||
log((CLOG_NOTE "stopping server"));
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CServer::run()
|
||||||
|
{
|
||||||
|
// check preconditions
|
||||||
|
{
|
||||||
|
CLock lock(&m_mutex);
|
||||||
|
assert(m_primary != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
log((CLOG_NOTE "starting server"));
|
||||||
|
|
||||||
// start listening for new clients
|
// start listening for new clients
|
||||||
startThread(new TMethodJob<CServer>(this, &CServer::acceptClients));
|
startThread(new TMethodJob<CServer>(this, &CServer::acceptClients));
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,15 @@ public:
|
||||||
|
|
||||||
// manipulators
|
// manipulators
|
||||||
|
|
||||||
|
// open the server's screen
|
||||||
|
bool open();
|
||||||
|
|
||||||
// start the server. does not return until quit() is called.
|
// start the server. does not return until quit() is called.
|
||||||
|
// this must be preceeded by a successful call to open().
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
// tell server to exit gracefully
|
// tell server to exit gracefully. this may only be called
|
||||||
|
// after a successful open().
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
// tell the server to shutdown. this is called in an emergency
|
// tell the server to shutdown. this is called in an emergency
|
||||||
|
|
|
@ -113,13 +113,18 @@ realMain(CMutex* mutex)
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
s_server = new CServer(s_name);
|
s_server = new CServer(s_name);
|
||||||
|
s_server->setConfig(s_config);
|
||||||
|
if (!s_server->open()) {
|
||||||
|
delete s_server;
|
||||||
|
s_server = NULL;
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
// run server (unlocked)
|
// run server (unlocked)
|
||||||
if (mutex != NULL) {
|
if (mutex != NULL) {
|
||||||
mutex->unlock();
|
mutex->unlock();
|
||||||
}
|
}
|
||||||
locked = false;
|
locked = false;
|
||||||
s_server->setConfig(s_config);
|
|
||||||
s_server->run();
|
s_server->run();
|
||||||
locked = true;
|
locked = true;
|
||||||
if (mutex != NULL) {
|
if (mutex != NULL) {
|
||||||
|
@ -129,7 +134,6 @@ realMain(CMutex* mutex)
|
||||||
// clean up
|
// clean up
|
||||||
delete s_server;
|
delete s_server;
|
||||||
s_server = NULL;
|
s_server = NULL;
|
||||||
CNetwork::cleanup();
|
|
||||||
CLog::setLock(NULL);
|
CLog::setLock(NULL);
|
||||||
s_logMutex = NULL;
|
s_logMutex = NULL;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +144,6 @@ realMain(CMutex* mutex)
|
||||||
}
|
}
|
||||||
delete s_server;
|
delete s_server;
|
||||||
s_server = NULL;
|
s_server = NULL;
|
||||||
CNetwork::cleanup();
|
|
||||||
CLog::setLock(NULL);
|
CLog::setLock(NULL);
|
||||||
s_logMutex = NULL;
|
s_logMutex = NULL;
|
||||||
throw;
|
throw;
|
||||||
|
@ -723,6 +726,8 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||||
result = restartableMain();
|
result = restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNetwork::cleanup();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,6 +770,8 @@ main(int argc, char** argv)
|
||||||
result = restartableMain();
|
result = restartableMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNetwork::cleanup();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue