Deskflow 1.26.0.314
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
SocketException.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2012 - 2016 Synergy App Ltd
5 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
6 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
7 */
8
9#pragma once
10
11#include "base/BaseException.h"
12#include "io/IOException.h"
13
14#include <QByteArray>
15
19class SocketException : public BaseException
20{
22};
23
25
29{
30public:
40
41 SocketAddressException(SocketError, const std::string &hostname, int port) noexcept;
42 ~SocketAddressException() throw() override = default;
43
45
46
48 SocketError getError() const noexcept;
50 std::string getHostname() const noexcept;
52 int getPort() const noexcept;
53
55
56protected:
57 // BaseException overrides
58 QString getWhat() const throw() override;
59
60private:
61 SocketError m_error;
62 std::string m_hostname;
63 int m_port;
64};
65
70{
71public:
73 {
74 // do nothing
75 }
76 explicit SocketIOCloseException(const QString &msg) : IOCloseException(msg), m_state(kFirst)
77 {
78 // do nothing
79 }
80 ~SocketIOCloseException() throw() override = default;
81
82 const char *what() const throw() override
83 {
84 if (m_state == kFirst) {
85 m_state = kFormat;
86 m_formatted = getWhat().toLocal8Bit();
87 m_state = kDone;
88 }
89 if (m_state == kDone) {
90 return m_formatted.constData();
91 } else {
93 }
94 }
95
96protected:
97 QString getWhat() const throw() override;
98
99private:
100 enum EState
101 {
102 kFirst,
103 kFormat,
104 kDone
105 };
106 mutable EState m_state;
107 mutable QByteArray m_formatted;
108};
109
114{
115public:
117 {
118 // do nothing
119 }
120 explicit SocketWithWhatException(const QString &msg) : SocketException(msg), m_state(kFirst)
121 {
122 // do nothing
123 }
124 ~SocketWithWhatException() throw() override = default;
125
126 const char *what() const throw() override
127 {
128 if (m_state == kFirst) {
129 m_state = kFormat;
130 m_formatted = getWhat().toLocal8Bit();
131 m_state = kDone;
132 }
133 if (m_state == kDone) {
134 return m_formatted.constData();
135 } else {
136 return SocketException::what();
137 }
138 }
139
140private:
141 enum EState
142 {
143 kFirst,
144 kFormat,
145 kDone
146 };
147 mutable EState m_state;
148 mutable QByteArray m_formatted;
149};
150
154class SocketBindException : public SocketWithWhatException
155{
157
158protected:
159 QString getWhat() const throw() override;
160};
161
166class SocketAddressInUseException : public SocketWithWhatException
167{
169
170protected:
171 QString getWhat() const throw() override;
172};
173
177class SocketConnectException : public SocketWithWhatException
178{
180
181protected:
182 QString getWhat() const throw() override;
183};
184
188class SocketCreateException : public SocketWithWhatException
189{
191
192protected:
193 QString getWhat() const throw() override;
194};
virtual QString getWhat() const noexcept
Get a human readable string describing the exception.
Definition BaseException.h:35
BaseException()
Use getWhat() as the result of what().
Definition BaseException.cpp:18
const char * what() const override
Reason for exception.
Definition BaseException.cpp:28
The IOCloseException - Thrown if a stream cannot be closed.
Definition IOException.h:25
SocketAddressException(SocketError, const std::string &hostname, int port) noexcept
Definition SocketException.cpp:16
SocketError
Failure codes.
Definition SocketException.h:33
@ NotFound
The hostname is unknown.
Definition SocketException.h:35
@ Unknown
Unknown error.
Definition SocketException.h:34
@ BadPort
The port is invalid.
Definition SocketException.h:38
@ Unsupported
The hostname is valid but has no supported address.
Definition SocketException.h:37
@ NoAddress
The hostname is valid but has no IP address.
Definition SocketException.h:36
QString getWhat() const override
Get a human readable string describing the exception.
Definition SocketException.cpp:39
SocketError getError() const noexcept
Get the error code.
Definition SocketException.cpp:24
int getPort() const noexcept
Get the port.
Definition SocketException.cpp:34
std::string getHostname() const noexcept
Get the hostname.
Definition SocketException.cpp:29
~SocketAddressException() override=default
SocketAddressInUseException Thrown when a socket cannot be bound to an address because the address is...
Definition SocketException.h:167
QString getWhat() const override
Get a human readable string describing the exception.
Definition SocketException.cpp:78
SocketBindException - Thrown when a socket cannot be bound to an address.
Definition SocketException.h:155
QString getWhat() const override
Get a human readable string describing the exception.
Definition SocketException.cpp:69
SocketConnectException - Thrown when a socket cannot connect to a remote endpoint.
Definition SocketException.h:178
QString getWhat() const override
Get a human readable string describing the exception.
Definition SocketException.cpp:87
SocketCreateException - Thrown when a socket cannot be created (by the operating system).
Definition SocketException.h:189
QString getWhat() const override
Get a human readable string describing the exception.
Definition SocketException.cpp:96
SocketException generic socket exception.
Definition SocketException.h:20
SocketIOCloseException(const QString &msg)
Definition SocketException.h:76
~SocketIOCloseException() override=default
SocketIOCloseException()
Definition SocketException.h:72
const char * what() const override
Definition SocketException.h:82
SocketWithWhatException(const QString &msg)
Definition SocketException.h:120
SocketWithWhatException()
Definition SocketException.h:116
~SocketWithWhatException() override=default
const char * what() const override
Definition SocketException.h:126
Definition Config.h:29