From 68e8a75daf6933d7ec4a3bd21cf12ed1ac880739 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 24 Oct 2009 20:03:45 +0000 Subject: Catch exceptions in inspsocket callbacks git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11966 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspsocket.cpp | 74 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 7485324a2..86104c54d 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -491,44 +491,52 @@ void StreamSocket::HandleEvent(EventType et, int errornum) if (!error.empty()) return; BufferedSocketError errcode = I_ERR_OTHER; - switch (et) - { - case EVENT_ERROR: + try { + switch (et) { - if (errornum == 0) - SetError("Connection closed"); - else - SetError(strerror(errornum)); - switch (errornum) + case EVENT_ERROR: { - case ETIMEDOUT: - errcode = I_ERR_TIMEOUT; - break; - case ECONNREFUSED: - case 0: - errcode = I_ERR_CONNECT; - break; - case EADDRINUSE: - errcode = I_ERR_BIND; - break; - case EPIPE: - case EIO: - errcode = I_ERR_WRITE; - break; + if (errornum == 0) + SetError("Connection closed"); + else + SetError(strerror(errornum)); + switch (errornum) + { + case ETIMEDOUT: + errcode = I_ERR_TIMEOUT; + break; + case ECONNREFUSED: + case 0: + errcode = I_ERR_CONNECT; + break; + case EADDRINUSE: + errcode = I_ERR_BIND; + break; + case EPIPE: + case EIO: + errcode = I_ERR_WRITE; + break; + } + break; + } + case EVENT_READ: + { + DoRead(); + break; + } + case EVENT_WRITE: + { + DoWrite(); + break; } - break; - } - case EVENT_READ: - { - DoRead(); - break; - } - case EVENT_WRITE: - { - DoWrite(); - break; } } + catch (CoreException& ex) + { + ServerInstance->Logs->Log("SOCKET", ERROR, "Caught exception in socket processing on FD %d - '%s'", + fd, ex.GetReason()); + SetError(ex.GetReason()); + } if (!error.empty()) { ServerInstance->Logs->Log("SOCKET", DEBUG, "Error on FD %d - '%s'", fd, error.c_str()); -- cgit v1.2.3