diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/rdr/Exception.cxx | 10 | ||||
-rw-r--r-- | common/rdr/Exception.h | 13 | ||||
-rw-r--r-- | common/rdr/TLSInStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/TLSInStream.h | 2 | ||||
-rw-r--r-- | common/rdr/TLSOutStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/TLSOutStream.h | 2 | ||||
-rw-r--r-- | common/rdr/ZlibOutStream.cxx | 2 | ||||
-rw-r--r-- | common/rfb/CConnection.cxx | 2 | ||||
-rw-r--r-- | common/rfb/DecodeManager.cxx | 8 | ||||
-rw-r--r-- | common/rfb/DecodeManager.h | 5 | ||||
-rw-r--r-- | common/rfb/SConnection.cxx | 4 | ||||
-rw-r--r-- | common/rfb/VNCSConnectionST.cxx | 32 | ||||
-rw-r--r-- | common/rfb/VNCServerST.cxx | 2 |
13 files changed, 39 insertions, 51 deletions
diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx index 53637cac..b2c7e7d0 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -42,16 +42,6 @@ using namespace rdr; -Exception::Exception(const char *message) -{ - snprintf(str_, sizeof(str_), "%s", message); -} - -Exception::Exception(const std::string& message) -{ - snprintf(str_, sizeof(str_), "%s", message.c_str()); -} - GAIException::GAIException(const char* s, int err_) : Exception(rfb::format("%s: %s (%d)", s, strerror(err_).c_str(), err_)), diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index bdb2061c..9ce0462a 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -1,6 +1,7 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. * Copyright (C) 2004 Red Hat Inc. * Copyright (C) 2010 TigerVNC Team + * Copyright 2015-2024 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,17 +22,15 @@ #ifndef __RDR_EXCEPTION_H__ #define __RDR_EXCEPTION_H__ +#include <stdexcept> #include <string> namespace rdr { - struct Exception { - Exception(const char* message); - Exception(const std::string& message); - virtual ~Exception() {} - virtual const char* what() const { return str_; } - private: - char str_[256]; + class Exception : public std::runtime_error { + public: + Exception(const char* what_arg) : std::runtime_error(what_arg) {} + Exception(const std::string& what_arg) : std::runtime_error(what_arg) {} }; struct PosixException : public Exception { diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index c0252122..3418c68e 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -61,10 +61,10 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) gnutls_transport_set_errno(self->session, e.err); self->saved_exception = new SocketException(e); return -1; - } catch (Exception& e) { + } catch (std::exception& e) { vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); - self->saved_exception = new Exception(e); + self->saved_exception = new std::exception(e); return -1; } diff --git a/common/rdr/TLSInStream.h b/common/rdr/TLSInStream.h index ca69ddde..2269b09d 100644 --- a/common/rdr/TLSInStream.h +++ b/common/rdr/TLSInStream.h @@ -41,7 +41,7 @@ namespace rdr { InStream* in; bool streamEmpty; - Exception* saved_exception; + std::exception* saved_exception; }; }; diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index 69d0fe3a..4c6c3f47 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -51,10 +51,10 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, gnutls_transport_set_errno(self->session, e.err); self->saved_exception = new SocketException(e); return -1; - } catch (Exception& e) { + } catch (std::exception& e) { vlog.error("Failure sending TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); - self->saved_exception = new Exception(e); + self->saved_exception = new std::exception(e); return -1; } diff --git a/common/rdr/TLSOutStream.h b/common/rdr/TLSOutStream.h index 35714238..659f16f0 100644 --- a/common/rdr/TLSOutStream.h +++ b/common/rdr/TLSOutStream.h @@ -42,7 +42,7 @@ namespace rdr { gnutls_session_t session; OutStream* out; - Exception* saved_exception; + std::exception* saved_exception; }; }; diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx index 0b167711..1b59f54e 100644 --- a/common/rdr/ZlibOutStream.cxx +++ b/common/rdr/ZlibOutStream.cxx @@ -54,7 +54,7 @@ ZlibOutStream::~ZlibOutStream() { try { flush(); - } catch (Exception&) { + } catch (std::exception&) { } deflateEnd(zs); delete zs; diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 7a9570ad..3a34740f 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -387,7 +387,7 @@ void CConnection::close() */ try { decoder.flush(); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { vlog.error("%s", e.what()); } diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 77beb620..6000063f 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -148,7 +148,7 @@ bool DecodeManager::decodeRect(const Rect& r, int encoding, try { if (!decoder->readRect(r, conn->getInStream(), conn->server, bufferStream)) return false; - } catch (rdr::Exception& e) { + } catch (std::exception& e) { throw Exception(format("Error reading rect: %s", e.what())); } @@ -243,7 +243,7 @@ void DecodeManager::logStats() iecPrefix(bytes, "B").c_str(), ratio); } -void DecodeManager::setThreadException(const rdr::Exception& e) +void DecodeManager::setThreadException(const std::exception& e) { os::AutoMutex a(queueMutex); @@ -260,7 +260,7 @@ void DecodeManager::throwThreadException() if (threadException == nullptr) return; - rdr::Exception e(*threadException); + std::exception e(*threadException); delete threadException; threadException = nullptr; @@ -318,7 +318,7 @@ void DecodeManager::DecodeThread::worker() entry->decoder->decodeRect(entry->rect, entry->bufferStream->data(), entry->bufferStream->length(), *entry->server, entry->pb); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { manager->setThreadException(e); } catch(...) { assert(false); diff --git a/common/rfb/DecodeManager.h b/common/rfb/DecodeManager.h index 5435bfc1..b11b7044 100644 --- a/common/rfb/DecodeManager.h +++ b/common/rfb/DecodeManager.h @@ -32,7 +32,6 @@ namespace os { } namespace rdr { - struct Exception; class MemOutStream; } @@ -55,7 +54,7 @@ namespace rfb { private: void logStats(); - void setThreadException(const rdr::Exception& e); + void setThreadException(const std::exception& e); void throwThreadException(); private: @@ -108,7 +107,7 @@ namespace rfb { }; std::list<DecodeThread*> threads; - rdr::Exception *threadException; + std::exception *threadException; }; } diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index d96ad178..c43ed493 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -223,7 +223,7 @@ void SConnection::processSecurityType(int secType) try { state_ = RFBSTATE_SECURITY; ssecurity = security.GetSSecurity(this, secType); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { failConnection(e.what()); } } @@ -293,7 +293,7 @@ void SConnection::handleAuthFailureTimeout(Timer* /*t*/) authFailureMsg.size()); } os->flush(); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { close(e.what()); return; } diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index e0fb69dc..9cdf289d 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -129,7 +129,7 @@ void VNCSConnectionST::close(const char* reason) if (sock->outStream().hasBufferedData()) vlog.error("Failed to flush remaining socket data on close"); } - } catch (rdr::Exception& e) { + } catch (std::exception& e) { vlog.error("Failed to flush remaining socket data on close: %s", e.what()); } @@ -146,7 +146,7 @@ bool VNCSConnectionST::init() { try { initialiseProtocol(); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { close(e.what()); return false; } @@ -189,7 +189,7 @@ void VNCSConnectionST::processMessages() writeFramebufferUpdate(); } catch (rdr::EndOfStream&) { close("Clean disconnection"); - } catch (rdr::Exception &e) { + } catch (std::exception& e) { close(e.what()); } } @@ -203,7 +203,7 @@ void VNCSConnectionST::flushSocket() // delayed because of congestion. if (!sock->outStream().hasBufferedData()) writeFramebufferUpdate(); - } catch (rdr::Exception &e) { + } catch (std::exception& e) { close(e.what()); } } @@ -252,7 +252,7 @@ void VNCSConnectionST::pixelBufferChange() updates.clear(); updates.add_changed(server->getPixelBuffer()->getRect()); writeFramebufferUpdate(); - } catch(rdr::Exception &e) { + } catch(std::exception& e) { close(e.what()); } } @@ -261,7 +261,7 @@ void VNCSConnectionST::writeFramebufferUpdateOrClose() { try { writeFramebufferUpdate(); - } catch(rdr::Exception &e) { + } catch(std::exception& e) { close(e.what()); } } @@ -271,7 +271,7 @@ void VNCSConnectionST::screenLayoutChangeOrClose(uint16_t reason) try { screenLayoutChange(reason); writeFramebufferUpdate(); - } catch(rdr::Exception &e) { + } catch(std::exception& e) { close(e.what()); } } @@ -280,7 +280,7 @@ void VNCSConnectionST::bellOrClose() { try { if (state() == RFBSTATE_NORMAL) writer()->writeBell(); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -290,7 +290,7 @@ void VNCSConnectionST::setDesktopNameOrClose(const char *name) try { setDesktopName(name); writeFramebufferUpdate(); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -300,7 +300,7 @@ void VNCSConnectionST::setCursorOrClose() try { setCursor(); writeFramebufferUpdate(); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -310,7 +310,7 @@ void VNCSConnectionST::setLEDStateOrClose(unsigned int state) try { setLEDState(state); writeFramebufferUpdate(); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -322,7 +322,7 @@ void VNCSConnectionST::requestClipboardOrClose() if (!accessCheck(AccessCutText)) return; if (!rfb::Server::acceptCutText) return; requestClipboard(); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -334,7 +334,7 @@ void VNCSConnectionST::announceClipboardOrClose(bool available) if (!accessCheck(AccessCutText)) return; if (!rfb::Server::sendCutText) return; announceClipboard(available); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -346,7 +346,7 @@ void VNCSConnectionST::sendClipboardDataOrClose(const char* data) if (!accessCheck(AccessCutText)) return; if (!rfb::Server::sendCutText) return; sendClipboardData(data); - } catch(rdr::Exception& e) { + } catch(std::exception& e) { close(e.what()); } } @@ -418,7 +418,7 @@ void VNCSConnectionST::approveConnectionOrClose(bool accept, { try { approveConnection(accept, reason); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { close(e.what()); } } @@ -805,7 +805,7 @@ void VNCSConnectionST::handleTimeout(Timer* t) if ((t == &congestionTimer) || (t == &losslessTimer)) writeFramebufferUpdate(); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { close(e.what()); } diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 66b05fae..f1ea2958 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -151,7 +151,7 @@ void VNCServerST::addSocket(network::Socket* sock, bool outgoing, AccessRights a os.writeU32(strlen(reason)); os.writeBytes((const uint8_t*)reason, strlen(reason)); os.flush(); - } catch (rdr::Exception&) { + } catch (std::exception&) { } sock->shutdown(); closingSockets.push_back(sock); |