Error messages: Fix ApiListener.

Refs #6070
This commit is contained in:
Michael Friedrich 2014-06-05 14:36:57 +02:00
parent f1e77a0579
commit bd916723f4
1 changed files with 24 additions and 10 deletions

View File

@ -51,8 +51,10 @@ void ApiListener::OnConfigLoaded(void)
if (!GetCrlPath().IsEmpty()) if (!GetCrlPath().IsEmpty())
AddCRLToSSLContext(m_SSLContext, GetCrlPath()); AddCRLToSSLContext(m_SSLContext, GetCrlPath());
if (!Endpoint::GetByName(GetIdentity())) if (!Endpoint::GetByName(GetIdentity())) {
BOOST_THROW_EXCEPTION(std::runtime_error("Endpoint object for '" + GetIdentity() + "' is missing.")); Log(LogCritical, "ApiListener", "Endpoint object for '" + GetIdentity() + "' is missing.");
return;
}
SyncZoneDirs(); SyncZoneDirs();
} }
@ -62,8 +64,10 @@ void ApiListener::OnConfigLoaded(void)
*/ */
void ApiListener::Start(void) void ApiListener::Start(void)
{ {
if (std::distance(DynamicType::GetObjects<ApiListener>().first, DynamicType::GetObjects<ApiListener>().second) > 1) if (std::distance(DynamicType::GetObjects<ApiListener>().first, DynamicType::GetObjects<ApiListener>().second) > 1) {
BOOST_THROW_EXCEPTION(std::runtime_error("Only one ApiListener object is allowed.")); Log(LogCritical, "ApiListener", "Only one ApiListener object is allowed.");
return;
}
DynamicObject::Start(); DynamicObject::Start();
@ -128,15 +132,23 @@ void ApiListener::AddListener(const String& service)
shared_ptr<SSL_CTX> sslContext = m_SSLContext; shared_ptr<SSL_CTX> sslContext = m_SSLContext;
if (!sslContext) if (!sslContext) {
BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddListener()")); Log(LogCritical, "ApiListener", "SSL context is required for AddListener()");
return;
}
std::ostringstream s; std::ostringstream s;
s << "Adding new listener: port " << service; s << "Adding new listener: port " << service;
Log(LogInformation, "ApiListener", s.str()); Log(LogInformation, "ApiListener", s.str());
TcpSocket::Ptr server = make_shared<TcpSocket>(); TcpSocket::Ptr server = make_shared<TcpSocket>();
server->Bind(service, AF_UNSPEC);
try {
server->Bind(service, AF_UNSPEC);
} catch(std::exception&) {
Log(LogCritical, "ApiListener", "Cannot bind tcp socket on '" + service + "'.");
return;
}
boost::thread thread(boost::bind(&ApiListener::ListenerThreadProc, this, server)); boost::thread thread(boost::bind(&ApiListener::ListenerThreadProc, this, server));
thread.detach(); thread.detach();
@ -170,8 +182,10 @@ void ApiListener::AddConnection(const String& node, const String& service)
shared_ptr<SSL_CTX> sslContext = m_SSLContext; shared_ptr<SSL_CTX> sslContext = m_SSLContext;
if (!sslContext) if (!sslContext) {
BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddConnection()")); Log(LogCritical, "ApiListener", "SSL context is required for AddListener()");
return;
}
} }
TcpSocket::Ptr client = make_shared<TcpSocket>(); TcpSocket::Ptr client = make_shared<TcpSocket>();
@ -183,7 +197,7 @@ void ApiListener::AddConnection(const String& node, const String& service)
std::ostringstream info, debug; std::ostringstream info, debug;
info << "Cannot connect to host '" << node << "' on port '" << service << "'"; info << "Cannot connect to host '" << node << "' on port '" << service << "'";
debug << info.str() << std::endl << DiagnosticInformation(ex); debug << info.str() << std::endl << DiagnosticInformation(ex);
Log(LogCritical, "remote", info.str()); Log(LogCritical, "ApiListener", info.str());
Log(LogDebug, "ApiListener", debug.str()); Log(LogDebug, "ApiListener", debug.str());
} }
} }