2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "base/XBase.h"
|
2025-03-19 22:11:47 +00:00
|
|
|
#include "common/Common.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "io/XIO.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//! Generic socket exception
|
|
|
|
|
XBASE_SUBCLASS(XSocket, XBase);
|
|
|
|
|
|
|
|
|
|
//! Socket bad address exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown when attempting to create an invalid network address.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class XSocketAddress : public XSocket
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Failure codes
|
2024-10-17 18:04:35 +00:00
|
|
|
enum EError
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
kUnknown, //!< Unknown error
|
|
|
|
|
kNotFound, //!< The hostname is unknown
|
|
|
|
|
kNoAddress, //!< The hostname is valid but has no IP address
|
|
|
|
|
kUnsupported, //!< The hostname is valid but has no supported address
|
|
|
|
|
kBadPort //!< The port is invalid
|
|
|
|
|
};
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-03-20 23:35:21 +00:00
|
|
|
XSocketAddress(EError, const std::string &hostname, int port) throw();
|
|
|
|
|
virtual ~XSocketAddress() throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! @name accessors
|
|
|
|
|
//@{
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Get the error code
|
|
|
|
|
EError getError() const throw();
|
|
|
|
|
//! Get the hostname
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string getHostname() const throw();
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Get the port
|
|
|
|
|
int getPort() const throw();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//@}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
protected:
|
2024-07-02 19:07:06 +00:00
|
|
|
// XBase overrides
|
2025-01-06 00:55:07 +00:00
|
|
|
virtual std::string getWhat() const throw();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
EError m_error;
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string m_hostname;
|
2024-07-02 19:07:06 +00:00
|
|
|
int m_port;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! I/O closing exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown if a stream cannot be closed.
|
|
|
|
|
*/
|
|
|
|
|
XBASE_SUBCLASS_FORMAT(XSocketIOClose, XIOClose);
|
|
|
|
|
|
|
|
|
|
//! Socket cannot bind address exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown when a socket cannot be bound to an address.
|
|
|
|
|
*/
|
|
|
|
|
XBASE_SUBCLASS_FORMAT(XSocketBind, XSocket);
|
|
|
|
|
|
|
|
|
|
//! Socket address in use exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown when a socket cannot be bound to an address because the address
|
|
|
|
|
is already in use.
|
|
|
|
|
*/
|
|
|
|
|
XBASE_SUBCLASS(XSocketAddressInUse, XSocketBind);
|
|
|
|
|
|
|
|
|
|
//! Cannot connect socket exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown when a socket cannot connect to a remote endpoint.
|
|
|
|
|
*/
|
|
|
|
|
XBASE_SUBCLASS_FORMAT(XSocketConnect, XSocket);
|
|
|
|
|
|
|
|
|
|
//! Cannot create socket exception
|
|
|
|
|
/*!
|
|
|
|
|
Thrown when a socket cannot be created (by the operating system).
|
|
|
|
|
*/
|
|
|
|
|
XBASE_SUBCLASS_FORMAT(XSocketCreate, XSocket);
|