Skip to content

Commit

Permalink
Consistently use SocketException for socket errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CendioOssman committed Oct 9, 2024
1 parent 6029d50 commit 56b3460
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions common/rdr/FdInStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions common/rdr/FdOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions common/rdr/TLSInStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions common/rdr/TLSOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion unix/tx/TXDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TXDialog : public TXWindow, public TXDeleteWindowCallback {
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;
Expand Down
2 changes: 1 addition & 1 deletion unix/vncconfig/vncconfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion unix/x0vncserver/x0vncserver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion vncviewer/vncviewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions win/rfb_win32/SocketManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 56b3460

Please sign in to comment.