cleaned up some minor bugs.

This commit is contained in:
crs
2002-06-21 17:55:47 +00:00
parent e0f66d162f
commit ede18cb7f3
7 changed files with 86 additions and 44 deletions

View File

@@ -55,30 +55,41 @@ CServer::~CServer()
// do nothing
}
bool
CServer::open()
{
// open the screen
try {
log((CLOG_INFO "opening screen"));
openPrimaryScreen();
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;
}
catch (XUnknownClient& e) {
// 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()));
return false;
}
}
void
CServer::run()
{
// check preconditions
{
CLock lock(&m_mutex);
assert(m_primary != NULL);
}
try {
log((CLOG_NOTE "starting server"));
// connect to primary screen
while (m_primary == NULL) {
try {
openPrimaryScreen();
}
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);
}
catch (XUnknownClient& e) {
// can't open screen yet. wait a few seconds to retry.
log((CLOG_CRIT "unknown screen name `%s'", e.getName().c_str()));
log((CLOG_NOTE "stopping server"));
return;
}
}
// start listening for new clients
startThread(new TMethodJob<CServer>(this, &CServer::acceptClients));

View File

@@ -27,10 +27,15 @@ public:
// manipulators
// open the server's screen
bool open();
// start the server. does not return until quit() is called.
// this must be preceeded by a successful call to open().
void run();
// tell server to exit gracefully
// tell server to exit gracefully. this may only be called
// after a successful open().
void quit();
// tell the server to shutdown. this is called in an emergency

View File

@@ -113,13 +113,18 @@ realMain(CMutex* mutex)
// create server
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)
if (mutex != NULL) {
mutex->unlock();
}
locked = false;
s_server->setConfig(s_config);
s_server->run();
locked = true;
if (mutex != NULL) {
@@ -129,7 +134,6 @@ realMain(CMutex* mutex)
// clean up
delete s_server;
s_server = NULL;
CNetwork::cleanup();
CLog::setLock(NULL);
s_logMutex = NULL;
}
@@ -140,7 +144,6 @@ realMain(CMutex* mutex)
}
delete s_server;
s_server = NULL;
CNetwork::cleanup();
CLog::setLock(NULL);
s_logMutex = NULL;
throw;
@@ -723,6 +726,8 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
result = restartableMain();
}
CNetwork::cleanup();
return result;
}
@@ -765,6 +770,8 @@ main(int argc, char** argv)
result = restartableMain();
}
CNetwork::cleanup();
return result;
}