diff options
Diffstat (limited to 'src/lib/net')
| -rw-r--r-- | src/lib/net/IDataSocket.h | 4 | ||||
| -rw-r--r-- | src/lib/net/NetworkAddress.cpp | 5 | ||||
| -rw-r--r-- | src/lib/net/NetworkAddress.h | 7 | ||||
| -rw-r--r-- | src/lib/net/SecureListenSocket.cpp | 3 | ||||
| -rw-r--r-- | src/lib/net/SecureSocket.cpp | 24 | ||||
| -rw-r--r-- | src/lib/net/SecureSocket.h | 18 | ||||
| -rw-r--r-- | src/lib/net/TCPSocket.cpp | 25 | ||||
| -rw-r--r-- | src/lib/net/TCPSocket.h | 3 | ||||
| -rw-r--r-- | src/lib/net/XSocket.cpp | 27 | ||||
| -rw-r--r-- | src/lib/net/XSocket.h | 15 |
10 files changed, 59 insertions, 72 deletions
diff --git a/src/lib/net/IDataSocket.h b/src/lib/net/IDataSocket.h index dc07df5..c77a99c 100644 --- a/src/lib/net/IDataSocket.h +++ b/src/lib/net/IDataSocket.h @@ -20,8 +20,8 @@ #include "net/ISocket.h" #include "io/IStream.h" -#include "base/String.h" #include "base/EventTypes.h" +#include <string> //! Data stream socket interface /*! @@ -33,7 +33,7 @@ public: class ConnectionFailedInfo { public: ConnectionFailedInfo(const char* what) : m_what(what) { } - String m_what; + std::string m_what; }; IDataSocket(IEventQueue* events) { } diff --git a/src/lib/net/NetworkAddress.cpp b/src/lib/net/NetworkAddress.cpp index 8d60567..c8ea9c6 100644 --- a/src/lib/net/NetworkAddress.cpp +++ b/src/lib/net/NetworkAddress.cpp @@ -96,7 +96,7 @@ NetworkAddress::NetworkAddress(const NetworkAddress& addr) : // do nothing } -NetworkAddress::NetworkAddress(const String& hostname, int port) : +NetworkAddress::NetworkAddress(const std::string& hostname, int port) : m_address(NULL), m_hostname(hostname), m_port(port) @@ -196,8 +196,7 @@ NetworkAddress::getPort() const return m_port; } -String -NetworkAddress::getHostname() const +std::string NetworkAddress::getHostname() const { return m_hostname; } diff --git a/src/lib/net/NetworkAddress.h b/src/lib/net/NetworkAddress.h index cbd15f5..87dc1e4 100644 --- a/src/lib/net/NetworkAddress.h +++ b/src/lib/net/NetworkAddress.h @@ -18,7 +18,6 @@ #pragma once -#include "base/String.h" #include "base/EventTypes.h" #include "arch/IArchNetwork.h" @@ -49,7 +48,7 @@ public: is thrown with an error of \c XSocketAddress::kBadPort. The hostname is not resolved by the c'tor; use \c resolve to do that. */ - NetworkAddress(const String& hostname, int port); + NetworkAddress(const std::string& hostname, int port); NetworkAddress(const NetworkAddress&); @@ -109,7 +108,7 @@ public: /*! Returns the hostname passed to the c'tor sans any port suffix. */ - String getHostname() const; + std::string getHostname() const; //@} @@ -118,6 +117,6 @@ private: private: ArchNetAddress m_address; - String m_hostname; + std::string m_hostname; int m_port; }; diff --git a/src/lib/net/SecureListenSocket.cpp b/src/lib/net/SecureListenSocket.cpp index 7af905e..a137f39 100644 --- a/src/lib/net/SecureListenSocket.cpp +++ b/src/lib/net/SecureListenSocket.cpp @@ -23,6 +23,7 @@ #include "net/TSocketMultiplexerMethodJob.h" #include "arch/XArch.h" #include "common/DataDirectories.h" +#include "base/String.h" static const char s_certificateDir[] = { "SSL" }; static const char s_certificateFilename[] = { "Barrier.pem" }; @@ -54,7 +55,7 @@ SecureListenSocket::accept() setListeningJob(); } - String certificateFilename = barrier::string::sprintf("%s/%s/%s", + std::string certificateFilename = barrier::string::sprintf("%s/%s/%s", DataDirectories::profile().c_str(), s_certificateDir, s_certificateFilename); diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 99f626e..855e16b 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -23,6 +23,7 @@ #include "mt/Lock.h" #include "arch/XArch.h" #include "base/Log.h" +#include "base/String.h" #include "common/DataDirectories.h" #include <openssl/ssl.h> @@ -328,8 +329,7 @@ SecureSocket::initSsl(bool server) initContext(server); } -bool -SecureSocket::loadCertificates(String& filename) +bool SecureSocket::loadCertificates(std::string& filename) { if (filename.empty()) { showError("ssl certificate is not specified"); @@ -341,7 +341,7 @@ SecureSocket::loadCertificates(String& filename) file.close(); if (!exist) { - String errorMsg("ssl certificate doesn't exist: "); + std::string errorMsg("ssl certificate doesn't exist: "); errorMsg.append(filename); showError(errorMsg.c_str()); return false; @@ -630,14 +630,13 @@ SecureSocket::showError(const char* reason) LOG((CLOG_ERR "%s", reason)); } - String error = getError(); + std::string error = getError(); if (!error.empty()) { LOG((CLOG_ERR "%s", error.c_str())); } } -String -SecureSocket::getError() +std::string SecureSocket::getError() { unsigned long e = ERR_get_error(); @@ -659,8 +658,7 @@ SecureSocket::disconnect() sendEvent(getEvents()->forIStream().inputShutdown()); } -void -SecureSocket::formatFingerprint(String& fingerprint, bool hex, bool separator) +void SecureSocket::formatFingerprint(std::string& fingerprint, bool hex, bool separator) { if (hex) { // to hexidecimal @@ -696,11 +694,11 @@ SecureSocket::verifyCertFingerprint() } // format fingerprint into hexdecimal format with colon separator - String fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen); + std::string fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen); formatFingerprint(fingerprint); LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str())); - String trustedServersFilename; + std::string trustedServersFilename; trustedServersFilename = barrier::string::sprintf( "%s/%s/%s", DataDirectories::profile().c_str(), @@ -711,7 +709,7 @@ SecureSocket::verifyCertFingerprint() LOG((CLOG_NOTE "trustedServersFilename: %s", trustedServersFilename.c_str() )); // check if this fingerprint exist - String fileLine; + std::string fileLine; std::ifstream file; file.open(trustedServersFilename.c_str()); @@ -761,7 +759,7 @@ MultiplexerJobStatus SecureSocket::serviceConnect(ISocketMultiplexerJob* job, // If status > 0, success if (status > 0) { sendEvent(m_events->forIDataSocket().secureConnected()); - return {true, newJob()}; + return newJobOrStopServicing(); } // Retry case @@ -793,7 +791,7 @@ MultiplexerJobStatus SecureSocket::serviceAccept(ISocketMultiplexerJob* job, // If status > 0, success if (status > 0) { sendEvent(m_events->forClientListener().accepted()); - return {true, newJob()}; + return newJobOrStopServicing(); } // Retry case diff --git a/src/lib/net/SecureSocket.h b/src/lib/net/SecureSocket.h index 773b508..c602e2d 100644 --- a/src/lib/net/SecureSocket.h +++ b/src/lib/net/SecureSocket.h @@ -39,23 +39,23 @@ public: ~SecureSocket(); // ISocket overrides - void close(); + void close() override; // IDataSocket overrides - virtual void connect(const NetworkAddress&); + virtual void connect(const NetworkAddress&) override; std::unique_ptr<ISocketMultiplexerJob> newJob() override; - bool isFatal() const { return m_fatal; } + bool isFatal() const override { return m_fatal; } void isFatal(bool b) { m_fatal = b; } bool isSecureReady(); void secureConnect(); void secureAccept(); int secureRead(void* buffer, int size, int& read); int secureWrite(const void* buffer, int size, int& wrote); - EJobResult doRead(); - EJobResult doWrite(); + EJobResult doRead() override; + EJobResult doWrite() override; void initSsl(bool server); - bool loadCertificates(String& CertFile); + bool loadCertificates(std::string& CertFile); private: // SSL @@ -66,11 +66,9 @@ private: bool showCertificate(); void checkResult(int n, int& retry); void showError(const char* reason = NULL); - String getError(); + std::string getError(); void disconnect(); - void formatFingerprint(String& fingerprint, - bool hex = true, - bool separator = true); + void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true); bool verifyCertFingerprint(); MultiplexerJobStatus serviceConnect(ISocketMultiplexerJob*, bool, bool, bool); diff --git a/src/lib/net/TCPSocket.cpp b/src/lib/net/TCPSocket.cpp index 4f4251a..09a8f17 100644 --- a/src/lib/net/TCPSocket.cpp +++ b/src/lib/net/TCPSocket.cpp @@ -403,6 +403,15 @@ void TCPSocket::setJob(std::unique_ptr<ISocketMultiplexerJob>&& job) } } +MultiplexerJobStatus TCPSocket::newJobOrStopServicing() +{ + auto new_job = newJob(); + if (new_job) + return {true, std::move(new_job)}; + else + return {false, {}}; +} + std::unique_ptr<ISocketMultiplexerJob> TCPSocket::newJob() { // note -- must have m_mutex locked on entry @@ -519,22 +528,14 @@ MultiplexerJobStatus TCPSocket::serviceConnecting(ISocketMultiplexerJob* job, bo catch (XArchNetwork& e) { sendConnectionFailedEvent(e.what()); onDisconnected(); - auto new_job = newJob(); - if (new_job) - return {true, std::move(new_job)}; - else - return {false, {}}; + return newJobOrStopServicing(); } } if (write) { sendEvent(m_events->forIDataSocket().connected()); onConnected(); - auto new_job = newJob(); - if (new_job) - return {true, std::move(new_job)}; - else - return {false, {}}; + return newJobOrStopServicing(); } return {true, {}}; @@ -548,7 +549,7 @@ MultiplexerJobStatus TCPSocket::serviceConnected(ISocketMultiplexerJob* job, if (error) { sendEvent(m_events->forISocket().disconnected()); onDisconnected(); - return {true, newJob()}; + return newJobOrStopServicing(); } EJobResult writeResult = kRetry; @@ -603,7 +604,7 @@ MultiplexerJobStatus TCPSocket::serviceConnected(ISocketMultiplexerJob* job, if (writeResult == kBreak || readResult == kBreak) { return {false, {}}; } else if (writeResult == kNew || readResult == kNew) { - return {true, newJob()}; + return newJobOrStopServicing(); } else { return {true, {}}; } diff --git a/src/lib/net/TCPSocket.h b/src/lib/net/TCPSocket.h index 2889135..0b98888 100644 --- a/src/lib/net/TCPSocket.h +++ b/src/lib/net/TCPSocket.h @@ -76,7 +76,8 @@ protected: void removeJob(); void setJob(std::unique_ptr<ISocketMultiplexerJob>&& job); - + MultiplexerJobStatus newJobOrStopServicing(); + bool isReadable() { return m_readable; } bool isWritable() { return m_writable; } diff --git a/src/lib/net/XSocket.cpp b/src/lib/net/XSocket.cpp index 13e0fc3..eed7a26 100644 --- a/src/lib/net/XSocket.cpp +++ b/src/lib/net/XSocket.cpp @@ -23,8 +23,7 @@ // XSocketAddress // -XSocketAddress::XSocketAddress(EError error, - const String& hostname, int port) _NOEXCEPT : +XSocketAddress::XSocketAddress(EError error, const std::string& hostname, int port) noexcept : m_error(error), m_hostname(hostname), m_port(port) @@ -32,26 +31,22 @@ XSocketAddress::XSocketAddress(EError error, // do nothing } -XSocketAddress::EError -XSocketAddress::getError() const throw() +XSocketAddress::EError XSocketAddress::getError() const noexcept { return m_error; } -String -XSocketAddress::getHostname() const throw() +std::string XSocketAddress::getHostname() const noexcept { return m_hostname; } -int -XSocketAddress::getPort() const throw() +int XSocketAddress::getPort() const noexcept { return m_port; } -String -XSocketAddress::getWhat() const throw() +std::string XSocketAddress::getWhat() const noexcept { static const char* s_errorID[] = { "XSocketAddressUnknown", @@ -77,8 +72,7 @@ XSocketAddress::getWhat() const throw() // XSocketIOClose // -String -XSocketIOClose::getWhat() const throw() +std::string XSocketIOClose::getWhat() const noexcept { return format("XSocketIOClose", "close: %{1}", what()); } @@ -88,8 +82,7 @@ XSocketIOClose::getWhat() const throw() // XSocketBind // -String -XSocketBind::getWhat() const throw() +std::string XSocketBind::getWhat() const noexcept { return format("XSocketBind", "cannot bind address: %{1}", what()); } @@ -99,8 +92,7 @@ XSocketBind::getWhat() const throw() // XSocketConnect // -String -XSocketConnect::getWhat() const throw() +std::string XSocketConnect::getWhat() const noexcept { return format("XSocketConnect", "cannot connect socket: %{1}", what()); } @@ -110,8 +102,7 @@ XSocketConnect::getWhat() const throw() // XSocketCreate // -String -XSocketCreate::getWhat() const throw() +std::string XSocketCreate::getWhat() const noexcept { return format("XSocketCreate", "cannot create socket: %{1}", what()); } diff --git a/src/lib/net/XSocket.h b/src/lib/net/XSocket.h index be02b5b..d12278e 100644 --- a/src/lib/net/XSocket.h +++ b/src/lib/net/XSocket.h @@ -20,7 +20,6 @@ #include "io/XIO.h" #include "base/XBase.h" -#include "base/String.h" #include "common/basic_types.h" //! Generic socket exception @@ -41,28 +40,28 @@ public: kBadPort //!< The port is invalid }; - XSocketAddress(EError, const String& hostname, int port) _NOEXCEPT; - virtual ~XSocketAddress() _NOEXCEPT { } + XSocketAddress(EError, const std::string& hostname, int port) noexcept; + virtual ~XSocketAddress() noexcept { } //! @name accessors //@{ //! Get the error code - EError getError() const throw(); + EError getError() const noexcept; //! Get the hostname - String getHostname() const throw(); + std::string getHostname() const noexcept; //! Get the port - int getPort() const throw(); + int getPort() const noexcept; //@} protected: // XBase overrides - virtual String getWhat() const throw(); + virtual std::string getWhat() const noexcept; private: EError m_error; - String m_hostname; + std::string m_hostname; int m_port; }; |
