refactor: XIO Classes => IOException Classes
This commit is contained in:
@ -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
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/EventTypes.h"
|
||||
#include "io/XIO.h"
|
||||
#include "io/IOException.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <vector>
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
36
src/lib/io/IOException.cpp
Normal file
36
src/lib/io/IOException.cpp
Normal file
@ -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");
|
||||
}
|
||||
60
src/lib/io/IOException.h
Normal file
60
src/lib/io/IOException.h
Normal file
@ -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;
|
||||
};
|
||||
@ -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");
|
||||
}
|
||||
@ -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;
|
||||
};
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user