deskflow/src/lib/net/XSocket.h

91 lines
2 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* 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
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "base/XBase.h"
2025-01-11 02:14:00 +00:00
#include "common/common.h"
#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.
*/
class XSocketAddress : public XSocket
{
2012-06-10 16:50:54 +00:00
public:
//! Failure codes
enum EError
{
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
XSocketAddress(EError, const std::string &hostname, int port) _NOEXCEPT;
virtual ~XSocketAddress() _NOEXCEPT
{
}
2012-06-10 16:50:54 +00:00
//! @name accessors
//@{
2012-06-10 16:50:54 +00:00
//! Get the error code
EError getError() const throw();
//! Get the hostname
std::string getHostname() const throw();
//! Get the port
int getPort() const throw();
2012-06-10 16:50:54 +00:00
//@}
2012-06-10 16:50:54 +00:00
protected:
// XBase overrides
virtual std::string getWhat() const throw();
2012-06-10 16:50:54 +00:00
private:
EError m_error;
std::string m_hostname;
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);