diff --git a/src/lib/deskflow/ClientApp.cpp b/src/lib/deskflow/ClientApp.cpp index d4934831c..a57b1c6f5 100644 --- a/src/lib/deskflow/ClientApp.cpp +++ b/src/lib/deskflow/ClientApp.cpp @@ -87,7 +87,7 @@ void ClientApp::parseArgs(int argc, const char *const *argv) // we'll try to resolve the address each time we connect to the // server. a bad port will never get better. patch by Brent // Priddy. - if (!args().m_restartable || e.getError() == XSocketAddress::kBadPort) { + if (!args().m_restartable || e.getError() == XSocketAddress::SocketError::BadPort) { LOG((CLOG_CRIT "%s: %s" BYE, args().m_pname, e.what(), args().m_pname)); m_bye(s_exitFailed); } diff --git a/src/lib/net/NetworkAddress.cpp b/src/lib/net/NetworkAddress.cpp index f0f4eddfe..b8e232839 100644 --- a/src/lib/net/NetworkAddress.cpp +++ b/src/lib/net/NetworkAddress.cpp @@ -43,7 +43,7 @@ NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostna try { m_port = std::stoi(m_hostname.substr(hostIt + 1)); } catch (...) { - throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::BadPort, m_hostname, m_port); } auto endHostnameIt = static_cast(hostIt); @@ -57,19 +57,19 @@ NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostna // bad syntax of ipv6 with port if (hostIt == std::string::npos) { - throw XSocketAddress(XSocketAddress::kUnknown, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::Unknown, m_hostname, m_port); } auto portSuffix = m_hostname.substr(hostIt + portDelimeter.size()); // port is implied but omitted if (portSuffix.empty()) { - throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::BadPort, m_hostname, m_port); } try { m_port = std::stoi(portSuffix); } catch (...) { // port is not a number - throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::BadPort, m_hostname, m_port); } auto endHostnameIt = static_cast(hostIt) - 1; @@ -78,7 +78,7 @@ NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostna // ensure that ipv6 link-local adress ended with scope id if (m_hostname.rfind("fe80:", 0) == 0 && m_hostname.find('%') == std::string::npos) { - throw XSocketAddress(XSocketAddress::kUnknown, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::Unknown, m_hostname, m_port); } } @@ -156,13 +156,13 @@ size_t NetworkAddress::resolve(size_t index) } } } catch (XArchNetworkNameUnknown &) { - throw XSocketAddress(XSocketAddress::kNotFound, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::NotFound, m_hostname, m_port); } catch (XArchNetworkNameNoAddress &) { - throw XSocketAddress(XSocketAddress::kNoAddress, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::NoAddress, m_hostname, m_port); } catch (XArchNetworkNameUnsupported &) { - throw XSocketAddress(XSocketAddress::kUnsupported, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::Unsupported, m_hostname, m_port); } catch (XArchNetworkName &) { - throw XSocketAddress(XSocketAddress::kUnknown, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::Unknown, m_hostname, m_port); } // set port in address @@ -205,6 +205,6 @@ void NetworkAddress::checkPort() const { // check port number if (m_port < 0 || m_port > 65535) { - throw XSocketAddress(XSocketAddress::kBadPort, m_hostname, m_port); + throw XSocketAddress(XSocketAddress::SocketError::BadPort, m_hostname, m_port); } } diff --git a/src/lib/net/XSocket.cpp b/src/lib/net/XSocket.cpp index ecc35cf68..bca845353 100644 --- a/src/lib/net/XSocket.cpp +++ b/src/lib/net/XSocket.cpp @@ -12,7 +12,7 @@ // XSocketAddress // -XSocketAddress::XSocketAddress(EError error, const std::string &hostname, int port) noexcept +XSocketAddress::XSocketAddress(SocketError error, const std::string &hostname, int port) noexcept : m_error(error), m_hostname(hostname), m_port(port) @@ -20,7 +20,7 @@ XSocketAddress::XSocketAddress(EError error, const std::string &hostname, int po // do nothing } -XSocketAddress::EError XSocketAddress::getError() const noexcept +XSocketAddress::SocketError XSocketAddress::getError() const noexcept { return m_error; } @@ -46,8 +46,9 @@ std::string XSocketAddress::getWhat() const throw() "unsupported address for: %{1}", "invalid port" // m_port may not be set to the bad port }; + const auto index = static_cast(m_error); return format( - s_errorID[m_error], s_errorMsg[m_error], m_hostname.c_str(), deskflow::string::sprintf("%d", m_port).c_str() + s_errorID[index], s_errorMsg[index], m_hostname.c_str(), deskflow::string::sprintf("%d", m_port).c_str() ); } diff --git a/src/lib/net/XSocket.h b/src/lib/net/XSocket.h index 95b55c8ad..013b2fe93 100644 --- a/src/lib/net/XSocket.h +++ b/src/lib/net/XSocket.h @@ -27,23 +27,23 @@ class XSocketAddress : public XSocket { public: //! Failure codes - enum EError + enum class SocketError { - 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 + Unknown, //!< Unknown error + NotFound, //!< The hostname is unknown + NoAddress, //!< The hostname is valid but has no IP address + Unsupported, //!< The hostname is valid but has no supported address + BadPort //!< The port is invalid }; - XSocketAddress(EError, const std::string &hostname, int port) noexcept; + XSocketAddress(SocketError, const std::string &hostname, int port) noexcept; ~XSocketAddress() throw() override = default; //! @name accessors //@{ //! Get the error code - EError getError() const noexcept; + SocketError getError() const noexcept; //! Get the hostname std::string getHostname() const noexcept; //! Get the port @@ -56,7 +56,7 @@ protected: std::string getWhat() const throw() override; private: - EError m_error; + SocketError m_error; std::string m_hostname; int m_port; };