diff --git a/src/lib/deskflow/ProtocolUtil.cpp b/src/lib/deskflow/ProtocolUtil.cpp index 922a63993..b79d3f2bd 100644 --- a/src/lib/deskflow/ProtocolUtil.cpp +++ b/src/lib/deskflow/ProtocolUtil.cpp @@ -93,7 +93,7 @@ bool ProtocolUtil::readf(deskflow::IStream *stream, const char *fmt, ...) try { vreadf(stream, fmt, args); result = true; - } catch (XIO &) { + } catch (IOException &) { result = false; } catch (const std::bad_alloc &) { result = false; @@ -430,7 +430,7 @@ void ProtocolUtil::read(deskflow::IStream *stream, void *vbuffer, uint32_t count // bail if stream has hungup if (n == 0) { LOG_DEBUG2("unexpected disconnect in readf(), %d bytes left", count); - throw XIOEndOfStream(); + throw IOEndOfStreamException(); } // prepare for next read diff --git a/src/lib/deskflow/ProtocolUtil.h b/src/lib/deskflow/ProtocolUtil.h index 15b7290a2..c768ddeef 100644 --- a/src/lib/deskflow/ProtocolUtil.h +++ b/src/lib/deskflow/ProtocolUtil.h @@ -8,7 +8,7 @@ #pragma once #include "base/EventTypes.h" -#include "io/XIO.h" +#include "io/IOException.h" #include #include @@ -98,7 +98,7 @@ private: Thrown by ProtocolUtil::readf() when the data being read does not match the format. */ -class XIOReadMismatch : public XIO +class XIOReadMismatch : public IOException { public: // XBase overrides diff --git a/src/lib/io/CMakeLists.txt b/src/lib/io/CMakeLists.txt index db3e5e6e0..fa2d6a03d 100644 --- a/src/lib/io/CMakeLists.txt +++ b/src/lib/io/CMakeLists.txt @@ -6,11 +6,11 @@ add_library(io STATIC Filesystem.cpp Filesystem.h + IOException.cpp + IOException.h IStream.h StreamBuffer.cpp StreamBuffer.h StreamFilter.cpp StreamFilter.h - XIO.cpp - XIO.h ) diff --git a/src/lib/io/IOException.cpp b/src/lib/io/IOException.cpp new file mode 100644 index 000000000..5e41ac1e9 --- /dev/null +++ b/src/lib/io/IOException.cpp @@ -0,0 +1,36 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers + * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. + * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#include "io/IOException.h" + +// +// IOClosedException +// + +std::string IOClosedException::getWhat() const throw() +{ + return format("IOClosedException", "already closed"); +} + +// +// IOEndOfStreamException +// + +std::string IOEndOfStreamException::getWhat() const throw() +{ + return format("IOEndOfStreamException", "reached end of stream"); +} + +// +// IOWouldBlockException +// + +std::string IOWouldBlockException::getWhat() const throw() +{ + return format("IOWouldBlockException", "stream operation would block"); +} diff --git a/src/lib/io/IOException.h b/src/lib/io/IOException.h new file mode 100644 index 000000000..a014ac8ce --- /dev/null +++ b/src/lib/io/IOException.h @@ -0,0 +1,60 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers + * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. + * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#pragma once + +#include "base/XBase.h" + +/** + * @brief The IOException class Generic i/o exception class + */ +class IOException : public XBase +{ + using XBase::XBase; +}; + +/** + * @brief The IOCloseException - Thrown if a stream cannot be closed. + */ +class IOCloseException : public IOException +{ + using IOException::IOException; +}; + +/** + * @brief IOClosedException - Thrown when attempting to close or perform I/O on an already closed. + */ +class IOClosedException : public IOException +{ + using IOException::IOException; + +protected: + std::string getWhat() const throw() override; +}; + +/** + * @brief IOEndOfStreamException - Thrown when attempting to read beyond the end of a stream. + */ +class IOEndOfStreamException : public IOException +{ + using IOException::IOException; + +protected: + std::string getWhat() const throw() override; +}; + +/** + * @brief IOWouldBlockException - Thrown if an operation on a stream would block. + */ +class IOWouldBlockException : public IOException +{ + using IOException::IOException; + +protected: + std::string getWhat() const throw() override; +}; diff --git a/src/lib/io/XIO.cpp b/src/lib/io/XIO.cpp deleted file mode 100644 index fcb1716d3..000000000 --- a/src/lib/io/XIO.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. - * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman - * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception - */ - -#include "io/XIO.h" - -// -// XIOClosed -// - -std::string XIOClosed::getWhat() const throw() -{ - return format("XIOClosed", "already closed"); -} - -// -// XIOEndOfStream -// - -std::string XIOEndOfStream::getWhat() const throw() -{ - return format("XIOEndOfStream", "reached end of stream"); -} - -// -// XIOWouldBlock -// - -std::string XIOWouldBlock::getWhat() const throw() -{ - return format("XIOWouldBlock", "stream operation would block"); -} diff --git a/src/lib/io/XIO.h b/src/lib/io/XIO.h deleted file mode 100644 index 94ac69eee..000000000 --- a/src/lib/io/XIO.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. - * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman - * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception - */ - -#pragma once - -#include "base/XBase.h" - -/** - * @brief The XIO class Generic i/o exception class - */ -class XIO : public XBase -{ - using XBase::XBase; -}; - -/** - * @brief The XIOClose - Thrown if a stream cannot be closed. - */ -class XIOClose : public XIO -{ - using XIO::XIO; -}; - -/** - * @brief XIOClosed - Thrown when attempting to close or perform I/O on an already closed. - */ -class XIOClosed : public XIO -{ - using XIO::XIO; - -protected: - std::string getWhat() const throw() override; -}; - -/** - * @brief XIOEndOfStream - Thrown when attempting to read beyond the end of a stream. - */ -class XIOEndOfStream : public XIO -{ - using XIO::XIO; - -protected: - std::string getWhat() const throw() override; -}; - -/** - * @brief XIOWouldBlock - Thrown if an operation on a stream would block. - */ -class XIOWouldBlock : public XIO -{ - using XIO::XIO; - -protected: - std::string getWhat() const throw() override; -}; diff --git a/src/lib/net/SocketException.h b/src/lib/net/SocketException.h index 8ed752879..f0192c705 100644 --- a/src/lib/net/SocketException.h +++ b/src/lib/net/SocketException.h @@ -10,7 +10,7 @@ #include "base/XBase.h" #include "common/Common.h" -#include "io/XIO.h" +#include "io/IOException.h" /** * @brief SocketException generic socket exception @@ -65,14 +65,14 @@ private: /** * @brief SocketIOCloseException - Thrown if a stream cannot be closed. */ -class SocketIOCloseException : public XIOClose +class SocketIOCloseException : public IOCloseException { public: - SocketIOCloseException() : XIOClose(), m_state(kDone) + SocketIOCloseException() : IOCloseException(), m_state(kDone) { // do nothing } - explicit SocketIOCloseException(const std::string &msg) : XIOClose(msg), m_state(kFirst) + explicit SocketIOCloseException(const std::string &msg) : IOCloseException(msg), m_state(kFirst) { // do nothing } @@ -88,7 +88,7 @@ public: if (m_state == kDone) { return m_formatted.c_str(); } else { - return XIOClose::what(); + return IOCloseException::what(); } } diff --git a/src/lib/net/TCPListenSocket.cpp b/src/lib/net/TCPListenSocket.cpp index 6c5755583..dac3a68a0 100644 --- a/src/lib/net/TCPListenSocket.cpp +++ b/src/lib/net/TCPListenSocket.cpp @@ -11,7 +11,7 @@ #include "arch/XArch.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "io/XIO.h" +#include "io/IOException.h" #include "net/NetworkAddress.h" #include "net/SocketException.h" #include "net/SocketMultiplexer.h" @@ -71,7 +71,7 @@ void TCPListenSocket::close() { std::scoped_lock lock{m_mutex}; if (m_socket == nullptr) { - throw XIOClosed(); + throw IOClosedException(); } try { m_socketMultiplexer->removeSocket(this); diff --git a/src/lib/server/ClientProxyUnknown.cpp b/src/lib/server/ClientProxyUnknown.cpp index dd6820eda..574b1d156 100644 --- a/src/lib/server/ClientProxyUnknown.cpp +++ b/src/lib/server/ClientProxyUnknown.cpp @@ -14,8 +14,8 @@ #include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolUtil.h" #include "deskflow/XDeskflow.h" +#include "io/IOException.h" #include "io/IStream.h" -#include "io/XIO.h" #include "server/ClientProxy1_0.h" #include "server/ClientProxy1_1.h" #include "server/ClientProxy1_2.h"