From 56b3460aa318b650f12833ba119fa6decb930148 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 10 Sep 2024 16:57:24 +0200 Subject: [PATCH] Consistently use SocketException for socket errors The behaviour is not consistent as Windows doesn't use errno for socket errors, but Unix systems do. Always use the same exception to keep things somewhat sane. --- common/rdr/FdInStream.cxx | 4 ++-- common/rdr/FdOutStream.cxx | 4 ++-- common/rdr/TLSInStream.cxx | 4 ++-- common/rdr/TLSOutStream.cxx | 4 ++-- unix/tx/TXDialog.h | 2 +- unix/vncconfig/vncconfig.cxx | 2 +- unix/x0vncserver/x0vncserver.cxx | 2 +- vncviewer/vncviewer.cxx | 2 +- win/rfb_win32/SocketManager.cxx | 10 +++++----- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx index 491dc008..bddee482 100644 --- a/common/rdr/FdInStream.cxx +++ b/common/rdr/FdInStream.cxx @@ -92,7 +92,7 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SystemException("select", errorNumber); + throw SocketException("select", errorNumber); if (n == 0) return 0; @@ -102,7 +102,7 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SystemException("read", errorNumber); + throw SocketException("read", errorNumber); if (n == 0) throw EndOfStream(); diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 1f60d45b..1b6049ca 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -117,7 +117,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SystemException("select", errorNumber); + throw SocketException("select", errorNumber); if (n == 0) return 0; @@ -134,7 +134,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && (errorNumber == EINTR)); if (n < 0) - throw SystemException("write", errorNumber); + throw SocketException("write", errorNumber); gettimeofday(&lastWrite, nullptr); diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index d13cee1f..f8f4fcf9 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -56,10 +56,10 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) in->readBytes((uint8_t*)data, size); } catch (EndOfStream&) { return 0; - } catch (SystemException &e) { + } catch (SocketException& e) { vlog.error("Failure reading TLS data: %s", e.str()); gnutls_transport_set_errno(self->session, e.err); - self->saved_exception = new SystemException(e); + self->saved_exception = new SocketException(e); return -1; } catch (Exception& e) { vlog.error("Failure reading TLS data: %s", e.str()); diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index c2f69310..ccb229e1 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -46,10 +46,10 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, try { out->writeBytes((const uint8_t*)data, size); out->flush(); - } catch (SystemException &e) { + } catch (SocketException& e) { vlog.error("Failure sending TLS data: %s", e.str()); gnutls_transport_set_errno(self->session, e.err); - self->saved_exception = new SystemException(e); + self->saved_exception = new SocketException(e); return -1; } catch (Exception& e) { vlog.error("Failure sending TLS data: %s", e.str()); diff --git a/unix/tx/TXDialog.h b/unix/tx/TXDialog.h index 720c50d0..3a22fd07 100644 --- a/unix/tx/TXDialog.h +++ b/unix/tx/TXDialog.h @@ -63,7 +63,7 @@ public: FD_ZERO(&rfds); FD_SET(ConnectionNumber(dpy), &rfds); int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr); - if (n < 0) throw rdr::SystemException("select",errno); + if (n < 0) throw rdr::SocketException("select", errno); } } return true; diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx index ab7c6315..1498bbdb 100644 --- a/unix/vncconfig/vncconfig.cxx +++ b/unix/vncconfig/vncconfig.cxx @@ -330,7 +330,7 @@ int main(int argc, char** argv) FD_ZERO(&rfds); FD_SET(ConnectionNumber(dpy), &rfds); int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, tvp); - if (n < 0) throw rdr::SystemException("select",errno); + if (n < 0) throw rdr::SocketException("select", errno); } XCloseDisplay(dpy); diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 802ea252..b4f48e5c 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -441,7 +441,7 @@ int main(int argc, char** argv) vlog.debug("Interrupted select() system call"); continue; } else { - throw rdr::SystemException("select", errno); + throw rdr::SocketException("select", errno); } } diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index ab95c0c6..fb358537 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -808,7 +808,7 @@ int main(int argc, char** argv) vlog.debug("Interrupted select() system call"); continue; } else { - throw rdr::SystemException("select", errno); + throw rdr::SocketException("select", errno); } } diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 57b65aef..2bc2f53e 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -67,7 +67,7 @@ void SocketManager::addListener(network::SocketListener* sock_, flags |= FD_ADDRESS_LIST_CHANGE; try { if (event && (WSAEventSelect(sock_->getFd(), event, flags) == SOCKET_ERROR)) - throw rdr::SystemException("Unable to select on listener", WSAGetLastError()); + throw rdr::SocketException("Unable to select on listener", WSAGetLastError()); // requestAddressChangeEvents MUST happen after WSAEventSelect, so that the socket is non-blocking if (acn) @@ -184,7 +184,7 @@ int SocketManager::checkTimeouts() { if (j->second.sock->outStream().hasBufferedData()) eventMask |= FD_WRITE; if (WSAEventSelect(j->second.sock->getFd(), j->first, eventMask) == SOCKET_ERROR) - throw rdr::SystemException("unable to adjust WSAEventSelect:%u", WSAGetLastError()); + throw rdr::SocketException("unable to adjust WSAEventSelect:%u", WSAGetLastError()); } } @@ -234,11 +234,11 @@ void SocketManager::processEvent(HANDLE event) { // Fetch why this event notification triggered if (WSAEnumNetworkEvents(ci.sock->getFd(), event, &network_events) == SOCKET_ERROR) - throw rdr::SystemException("unable to get WSAEnumNetworkEvents:%u", WSAGetLastError()); + throw rdr::SocketException("unable to get WSAEnumNetworkEvents:%u", WSAGetLastError()); // Cancel event notification for this socket if (WSAEventSelect(ci.sock->getFd(), event, 0) == SOCKET_ERROR) - throw rdr::SystemException("unable to disable WSAEventSelect:%u", WSAGetLastError()); + throw rdr::SocketException("unable to disable WSAEventSelect:%u", WSAGetLastError()); // Reset the event object WSAResetEvent(event); @@ -266,7 +266,7 @@ void SocketManager::processEvent(HANDLE event) { if (ci.sock->outStream().hasBufferedData()) eventMask |= FD_WRITE; if (WSAEventSelect(ci.sock->getFd(), event, eventMask) == SOCKET_ERROR) - throw rdr::SystemException("unable to re-enable WSAEventSelect:%u", WSAGetLastError()); + throw rdr::SocketException("unable to re-enable WSAEventSelect:%u", WSAGetLastError()); } catch (rdr::Exception& e) { vlog.error("%s", e.str()); remSocket(ci.sock); -- 2.39.5