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
|
|
|
#include "net/XSocket.h"
|
2014-03-21 08:32:36 +00:00
|
|
|
#include "base/String.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// XSocketAddress
|
|
|
|
|
//
|
|
|
|
|
|
2025-03-20 23:35:21 +00:00
|
|
|
XSocketAddress::XSocketAddress(EError error, const std::string &hostname, int port) throw()
|
|
|
|
|
: m_error(error),
|
|
|
|
|
m_hostname(hostname),
|
|
|
|
|
m_port(port)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
XSocketAddress::EError XSocketAddress::getError() const throw()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return m_error;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketAddress::getHostname() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
return m_hostname;
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
int XSocketAddress::getPort() const throw()
|
|
|
|
|
{
|
|
|
|
|
return m_port;
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketAddress::getWhat() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
static const char *s_errorID[] = {
|
2024-10-17 18:04:35 +00:00
|
|
|
"XSocketAddressUnknown", "XSocketAddressNotFound", "XSocketAddressNoAddress", "XSocketAddressUnsupported",
|
|
|
|
|
"XSocketAddressBadPort"
|
|
|
|
|
};
|
2024-07-02 19:07:06 +00:00
|
|
|
static const char *s_errorMsg[] = {
|
2024-10-17 18:04:35 +00:00
|
|
|
"unknown error for: %{1}:%{2}", "address not found for: %{1}", "no address for: %{1}",
|
|
|
|
|
"unsupported address for: %{1}",
|
2024-07-02 19:07:06 +00:00
|
|
|
"invalid port" // m_port may not be set to the bad port
|
|
|
|
|
};
|
2024-07-16 13:36:44 +00:00
|
|
|
return format(
|
2024-10-17 18:04:35 +00:00
|
|
|
s_errorID[m_error], s_errorMsg[m_error], m_hostname.c_str(), deskflow::string::sprintf("%d", m_port).c_str()
|
|
|
|
|
);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// XSocketIOClose
|
|
|
|
|
//
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketIOClose::getWhat() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return format("XSocketIOClose", "close: %{1}", what());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// XSocketBind
|
|
|
|
|
//
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketBind::getWhat() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return format("XSocketBind", "cannot bind address: %{1}", what());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-29 08:25:40 +00:00
|
|
|
//
|
|
|
|
|
// XSocketAddressInUse
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
std::string XSocketAddressInUse::getWhat() const throw()
|
|
|
|
|
{
|
|
|
|
|
return format("XSocketAddressInUse", "cannot bind address: %{1}", what());
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
// XSocketConnect
|
|
|
|
|
//
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketConnect::getWhat() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return format("XSocketConnect", "cannot connect socket: %{1}", what());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// XSocketCreate
|
|
|
|
|
//
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string XSocketCreate::getWhat() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return format("XSocketCreate", "cannot create socket: %{1}", what());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|