refactor: XIO Classes => IOException Classes
This commit is contained in:
parent
813b0c3828
commit
1b04b1137c
10 changed files with 110 additions and 108 deletions
|
|
@ -93,7 +93,7 @@ bool ProtocolUtil::readf(deskflow::IStream *stream, const char *fmt, ...)
|
||||||
try {
|
try {
|
||||||
vreadf(stream, fmt, args);
|
vreadf(stream, fmt, args);
|
||||||
result = true;
|
result = true;
|
||||||
} catch (XIO &) {
|
} catch (IOException &) {
|
||||||
result = false;
|
result = false;
|
||||||
} catch (const std::bad_alloc &) {
|
} catch (const std::bad_alloc &) {
|
||||||
result = false;
|
result = false;
|
||||||
|
|
@ -430,7 +430,7 @@ void ProtocolUtil::read(deskflow::IStream *stream, void *vbuffer, uint32_t count
|
||||||
// bail if stream has hungup
|
// bail if stream has hungup
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
LOG_DEBUG2("unexpected disconnect in readf(), %d bytes left", count);
|
LOG_DEBUG2("unexpected disconnect in readf(), %d bytes left", count);
|
||||||
throw XIOEndOfStream();
|
throw IOEndOfStreamException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for next read
|
// prepare for next read
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/EventTypes.h"
|
#include "base/EventTypes.h"
|
||||||
#include "io/XIO.h"
|
#include "io/IOException.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -98,7 +98,7 @@ private:
|
||||||
Thrown by ProtocolUtil::readf() when the data being read does not
|
Thrown by ProtocolUtil::readf() when the data being read does not
|
||||||
match the format.
|
match the format.
|
||||||
*/
|
*/
|
||||||
class XIOReadMismatch : public XIO
|
class XIOReadMismatch : public IOException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// XBase overrides
|
// XBase overrides
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
add_library(io STATIC
|
add_library(io STATIC
|
||||||
Filesystem.cpp
|
Filesystem.cpp
|
||||||
Filesystem.h
|
Filesystem.h
|
||||||
|
IOException.cpp
|
||||||
|
IOException.h
|
||||||
IStream.h
|
IStream.h
|
||||||
StreamBuffer.cpp
|
StreamBuffer.cpp
|
||||||
StreamBuffer.h
|
StreamBuffer.h
|
||||||
StreamFilter.cpp
|
StreamFilter.cpp
|
||||||
StreamFilter.h
|
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 "base/XBase.h"
|
||||||
#include "common/Common.h"
|
#include "common/Common.h"
|
||||||
#include "io/XIO.h"
|
#include "io/IOException.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SocketException generic socket exception
|
* @brief SocketException generic socket exception
|
||||||
|
|
@ -65,14 +65,14 @@ private:
|
||||||
/**
|
/**
|
||||||
* @brief SocketIOCloseException - Thrown if a stream cannot be closed.
|
* @brief SocketIOCloseException - Thrown if a stream cannot be closed.
|
||||||
*/
|
*/
|
||||||
class SocketIOCloseException : public XIOClose
|
class SocketIOCloseException : public IOCloseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SocketIOCloseException() : XIOClose(), m_state(kDone)
|
SocketIOCloseException() : IOCloseException(), m_state(kDone)
|
||||||
{
|
{
|
||||||
// do nothing
|
// 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
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ public:
|
||||||
if (m_state == kDone) {
|
if (m_state == kDone) {
|
||||||
return m_formatted.c_str();
|
return m_formatted.c_str();
|
||||||
} else {
|
} else {
|
||||||
return XIOClose::what();
|
return IOCloseException::what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include "arch/XArch.h"
|
#include "arch/XArch.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "io/XIO.h"
|
#include "io/IOException.h"
|
||||||
#include "net/NetworkAddress.h"
|
#include "net/NetworkAddress.h"
|
||||||
#include "net/SocketException.h"
|
#include "net/SocketException.h"
|
||||||
#include "net/SocketMultiplexer.h"
|
#include "net/SocketMultiplexer.h"
|
||||||
|
|
@ -71,7 +71,7 @@ void TCPListenSocket::close()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{m_mutex};
|
std::scoped_lock lock{m_mutex};
|
||||||
if (m_socket == nullptr) {
|
if (m_socket == nullptr) {
|
||||||
throw XIOClosed();
|
throw IOClosedException();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
m_socketMultiplexer->removeSocket(this);
|
m_socketMultiplexer->removeSocket(this);
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
#include "deskflow/ProtocolTypes.h"
|
#include "deskflow/ProtocolTypes.h"
|
||||||
#include "deskflow/ProtocolUtil.h"
|
#include "deskflow/ProtocolUtil.h"
|
||||||
#include "deskflow/XDeskflow.h"
|
#include "deskflow/XDeskflow.h"
|
||||||
|
#include "io/IOException.h"
|
||||||
#include "io/IStream.h"
|
#include "io/IStream.h"
|
||||||
#include "io/XIO.h"
|
|
||||||
#include "server/ClientProxy1_0.h"
|
#include "server/ClientProxy1_0.h"
|
||||||
#include "server/ClientProxy1_1.h"
|
#include "server/ClientProxy1_1.h"
|
||||||
#include "server/ClientProxy1_2.h"
|
#include "server/ClientProxy1_2.h"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue