Changed server to fail with an error if in can't bind() the listen

socket for any reason other than it's in use.
This commit is contained in:
crs
2002-10-17 21:37:31 +00:00
parent 586a5a81ab
commit 1d7f3d2aaf
2 changed files with 53 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
CServer::CServer(const CString& serverName) :
m_name(serverName),
m_error(false),
m_bindTimeout(5.0 * 60.0),
m_screenFactory(NULL),
m_socketFactory(NULL),
@@ -161,6 +162,12 @@ CServer::mainLoop()
throw;
}
#undef FINALLY
// throw if there was an error
if (m_error) {
LOG((CLOG_DEBUG "forwarding child thread exception"));
throw XServerRethrow();
}
}
void
@@ -169,6 +176,16 @@ CServer::exitMainLoop()
m_primaryClient->exitMainLoop();
}
void
CServer::exitMainLoopWithError()
{
{
CLock lock(&m_mutex);
m_error = true;
}
exitMainLoop();
}
void
CServer::close()
{
@@ -1186,7 +1203,7 @@ CServer::acceptClients(void*)
listen->bind(m_config.getSynergyAddress());
break;
}
catch (XSocketBind& e) {
catch (XSocketAddressInUse& e) {
LOG((CLOG_WARN "bind failed: %s", e.getErrstr()));
// give up if we've waited too long
@@ -1220,7 +1237,7 @@ CServer::acceptClients(void*)
catch (XBase& e) {
LOG((CLOG_ERR "cannot listen for clients: %s", e.what()));
delete listen;
exitMainLoop();
exitMainLoopWithError();
}
catch (...) {
delete listen;
@@ -1505,7 +1522,7 @@ CServer::acceptHTTPClients(void*)
catch (XBase& e) {
LOG((CLOG_ERR "cannot listen for HTTP clients: %s", e.what()));
delete listen;
exitMainLoop();
exitMainLoopWithError();
}
catch (...) {
delete listen;
@@ -1691,6 +1708,17 @@ CServer::removeConnection(const CString& name)
}
//
// CServer::CClipboardInfo
//
CString
CServer::XServerRethrow::getWhat() const throw()
{
return format("XServerRethrow", "child thread failed");
}
//
// CServer::CClipboardInfo
//