From 6029d50080bb795524d6cefe8d6b4b9b88475bdd Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 10 Sep 2024 17:05:39 +0200 Subject: [PATCH] Move SocketException to rdr Socket APIs are used in more places than the abstraction in common/network. Make it easier to use this exception class by putting it in a more common place. --- common/network/Socket.cxx | 6 +++--- common/network/Socket.h | 5 ----- common/rdr/Exception.h | 4 ++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 8da44366..8bb96763 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -53,7 +53,7 @@ void network::initSockets() { WSADATA initResult; if (WSAStartup(requiredVersion, &initResult) != 0) - throw SocketException("unable to initialise Winsock2", errorNumber); + throw rdr::SocketException("unable to initialise Winsock2", errorNumber); #else signal(SIGPIPE, SIG_IGN); #endif @@ -161,7 +161,7 @@ Socket* SocketListener::accept() { // Accept an incoming connection if ((new_sock = ::accept(fd, nullptr, nullptr)) < 0) - throw SocketException("unable to accept new connection", errorNumber); + throw rdr::SocketException("unable to accept new connection", errorNumber); // Create the socket object & check connection is allowed Socket* s = createSocket(new_sock); @@ -179,7 +179,7 @@ void SocketListener::listen(int sock) if (::listen(sock, 5) < 0) { int e = errorNumber; closesocket(sock); - throw SocketException("unable to set socket to listening mode", e); + throw rdr::SocketException("unable to set socket to listening mode", e); } fd = sock; diff --git a/common/network/Socket.h b/common/network/Socket.h index 7085d73a..34b8db8e 100644 --- a/common/network/Socket.h +++ b/common/network/Socket.h @@ -26,7 +26,6 @@ #include #include #include -#include namespace network { @@ -107,10 +106,6 @@ namespace network { ConnectionFilter* filter; }; - struct SocketException : public rdr::SystemException { - SocketException(const char* text, int err_) : rdr::SystemException(text, err_) {} - }; - } #endif // __NETWORK_SOCKET_H__ diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index f1a167e5..1202c37c 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -37,6 +37,10 @@ namespace rdr { SystemException(const char* s, int err_); }; + struct SocketException : public SystemException { + SocketException(const char* text, int err_) : SystemException(text, err_) {} + }; + struct GAIException : public Exception { int err; GAIException(const char* s, int err_); -- 2.39.5