From f32149117a0b32a26a7695760f29d1a2b10332c5 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 31 Jul 2011 04:00:35 -0400 Subject: [PATCH] Fixed error message from being unable to connect --- modules/extra/m_ssl.cpp | 4 +++- src/main.cpp | 22 +++++++++++++--------- src/sockets.cpp | 7 ++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/extra/m_ssl.cpp b/modules/extra/m_ssl.cpp index eb723a341..41bc49993 100644 --- a/modules/extra/m_ssl.cpp +++ b/modules/extra/m_ssl.cpp @@ -301,7 +301,7 @@ void SSLSocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int return; } - throw SocketException("Unable to connect to server: " + Anope::string(ERR_error_string(ERR_get_error(), NULL))); + s->ProcessError(); } IO->connected = 1; @@ -326,6 +326,8 @@ int SSLSocketIO::Connected(ConnectionSocket *s) int error = SSL_get_error(IO->sslsock, ret); if (ret == -1 && (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE)) return 0; + + s->ProcessError(); return -1; } IO->connected = 1; diff --git a/src/main.cpp b/src/main.cpp index 0c1db63ea..a33f1dff4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,7 +96,15 @@ class ReconnectTimer : public Timer void Tick(time_t) { - Connect(); + try + { + Connect(); + } + catch (const SocketException &ex) + { + quitmsg = ex.GetReason(); + quitting = true; + } } }; @@ -343,13 +351,9 @@ int main(int ac, char **av, char **envp) } catch (const SocketException &ex) { - Log() << ex.GetReason(); - ModuleManager::UnloadAll(); - SocketEngine::Shutdown(); - for (Module *m; (m = ModuleManager::FindFirstOf(PROTOCOL)) != NULL;) - ModuleManager::UnloadModule(m, NULL); - ModuleManager::CleanupRuntimeDirectory(); - return -1; + quitmsg = ex.GetReason(); + quitting = true; + return_code = -1; } started = true; @@ -415,5 +419,5 @@ int main(int ac, char **av, char **envp) return_code = -1; } - return 0; + return return_code; } diff --git a/src/sockets.cpp b/src/sockets.cpp index 122d6b646..e95c9f7a9 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -324,7 +324,7 @@ void SocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int por if (c == -1) { if (Anope::LastErrorCode() != EINPROGRESS) - throw SocketException("Error connecting to server: " + Anope::LastError()); + s->OnError(Anope::LastError()); else SocketEngine::MarkWritable(s); } @@ -718,6 +718,11 @@ bool ConnectionSocket::ProcessWrite() */ void ConnectionSocket::ProcessError() { + int optval = 0; + socklen_t optlen = sizeof(optval); + getsockopt(this->GetFD(), SOL_SOCKET, SO_ERROR, &optval, &optlen); + errno = optval; + this->OnError(optval ? Anope::LastError() : ""); } /** Called on a successful connect