server->Listen();
for (;;) {
- Socket::Ptr client = server->Accept();
-
- Log(LogNotice, "LivestatusListener", "Client connected");
-
- Utility::QueueAsyncCallback(boost::bind(&LivestatusListener::ClientHandler, this, client));
+ try {
+ Socket::Ptr client = server->Accept();
+ Log(LogNotice, "LivestatusListener", "Client connected");
+ Utility::QueueAsyncCallback(boost::bind(&LivestatusListener::ClientHandler, this, client));
+ } catch (std::exception&) {
+ Log(LogCritical, "ListenerListener", "Cannot accept new connection.");
+ }
}
}
if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK) {
try {
stream->Write(data.CStr(), data.GetLength());
- } catch (const std::exception& ex) {
- std::ostringstream info;
- info << "Exception thrown while writing to the livestatus socket: " << std::endl
- << DiagnosticInformation(ex);
- Log(LogCritical, "LivestatusQuery", info.str());
+ } catch (const std::exception&) {
+ Log(LogCritical, "LivestatusQuery", "Cannot write to tcp socket.");
}
}
}
try {
stream->Write(header.CStr(), header.GetLength());
- } catch (const std::exception& ex) {
- std::ostringstream info;
- info << "Exception thrown while writing to the livestatus socket: " << std::endl
- << DiagnosticInformation(ex);
- Log(LogCritical, "LivestatusQuery", info.str());
+ } catch (const std::exception&) {
+ Log(LogCritical, "LivestatusQuery", "Cannot write to tcp socket.");
}
}
try {
if (m_Stream) {
m_Stream->Write("\n", 1);
- Log(LogNotice, "GraphiteWriter", "GraphiteWriter already connected on socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
+ Log(LogNotice, "GraphiteWriter", "Already connected on socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
return;
}
- } catch (const std::exception& ex) {
- Log(LogWarning, "GraphiteWriter", "GraphiteWriter socket on host '" + GetHost() + "' port '" + GetPort() + "' gone. Attempting to reconnect.");
+ } catch (const std::exception&) {
+ Log(LogWarning, "GraphiteWriter", "Socket on host '" + GetHost() + "' port '" + GetPort() + "' gone. Attempting to reconnect.");
}
TcpSocket::Ptr socket = make_shared<TcpSocket>();
- Log(LogNotice, "GraphiteWriter", "GraphiteWriter: Reconnect to tcp socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
- socket->Connect(GetHost(), GetPort());
+ Log(LogNotice, "GraphiteWriter", "Reconnect to tcp socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
+
+ try {
+ socket->Connect(GetHost(), GetPort());
+ } catch (std::exception&) {
+ Log(LogCritical, "GraphiteWriter", "Can't connect to tcp socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
+ return;
+ }
m_Stream = make_shared<NetworkStream>(socket);
}
try {
m_Stream->Write(metric.CStr(), metric.GetLength());
} catch (const std::exception& ex) {
- std::ostringstream msgbuf;
- msgbuf << "Exception thrown while writing to the Graphite socket: " << std::endl
- << DiagnosticInformation(ex);
-
- Log(LogCritical, "GraphiteWriter", msgbuf.str());
+ Log(LogCritical, "GraphiteWriter", "Cannot write to tcp socket on host '" + GetHost() + "' port '" + GetPort() + "'.");
m_Stream.reset();
}
#endif /* _WIN32 */
}
- return GetAddressFromSockaddr((sockaddr *)&sin, len);
+ String address;
+ try {
+ address = GetAddressFromSockaddr((sockaddr *)&sin, len);
+ } catch (std::exception&) {
+ /* already logged */
+ }
+
+ return address;
}
/**
#endif /* _WIN32 */
}
- return GetAddressFromSockaddr((sockaddr *)&sin, len);
+ String address;
+ try {
+ address = GetAddressFromSockaddr((sockaddr *)&sin, len);
+ } catch (std::exception&) {
+ /* already logged */
+ }
+
+ return address;
}
/**
switch (err) {
case SSL_ERROR_WANT_READ:
- m_Socket->Poll(true, false);
+ try {
+ m_Socket->Poll(true, false);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_WANT_WRITE:
- m_Socket->Poll(false, true);
+ try {
+ m_Socket->Poll(false, true);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_ZERO_RETURN:
Close();
if (rc <= 0) {
switch (err) {
case SSL_ERROR_WANT_READ:
- m_Socket->Poll(true, false);
+ try {
+ m_Socket->Poll(true, false);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_WANT_WRITE:
- m_Socket->Poll(false, true);
+ try {
+ m_Socket->Poll(false, true);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_ZERO_RETURN:
Close();
if (rc <= 0) {
switch (err) {
case SSL_ERROR_WANT_READ:
- m_Socket->Poll(true, false);
+ try {
+ m_Socket->Poll(true, false);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_WANT_WRITE:
- m_Socket->Poll(false, true);
+ try {
+ m_Socket->Poll(false, true);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_ZERO_RETURN:
Close();
switch (err) {
case SSL_ERROR_WANT_READ:
- m_Socket->Poll(true, false);
+ try {
+ m_Socket->Poll(true, false);
+ } catch (std::exception&) {}
continue;
case SSL_ERROR_WANT_WRITE:
- m_Socket->Poll(false, true);
+ try {
+ m_Socket->Poll(false, true);
+ } catch (std::exception&) {}
continue;
default:
goto close_socket;
server->Listen();
for (;;) {
- Socket::Ptr client = server->Accept();
-
- Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleServer));
+ try {
+ Socket::Ptr client = server->Accept();
+ Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleServer));
+ } catch (std::exception&) {
+ Log(LogCritical, "ApiListener", "Cannot accept new connection.");
+ }
}
}