This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new 6122245 GEODE-8548: Avoid hostname resolution in TcpConn (#659)
6122245 is described below
commit 6122245ddf0c55fd1e07ae1daae25d67db7889be
Author: Mario Salazar de Torres <[email protected]>
AuthorDate: Thu Oct 1 16:28:26 2020 +0200
GEODE-8548: Avoid hostname resolution in TcpConn (#659)
- Calling get_host_name() in TcpConn::connect involves a system call that
might take several seconds to complete.
- So endpoint is stored instead upon TcpConn construction and used later
instead of making the system call.
- (pdxcodemonkey) Note that the call in question was buried in use of a
LOG* macro, which is not best practice
---
cppcache/src/TcpConn.cpp | 6 +++---
cppcache/src/TcpConn.hpp | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/cppcache/src/TcpConn.cpp b/cppcache/src/TcpConn.cpp
index 76acc9f..d6e709e 100644
--- a/cppcache/src/TcpConn.cpp
+++ b/cppcache/src/TcpConn.cpp
@@ -129,6 +129,7 @@ TcpConn::TcpConn(const std::string& address,
: stream_(nullptr),
maxBuffSizePool_(maxBuffSizePool),
inetAddress_(address.c_str()),
+ endpoint_(address),
timeout_(waitSeconds) {}
TcpConn::TcpConn(const std::string& hostname, uint16_t port,
@@ -136,6 +137,7 @@ TcpConn::TcpConn(const std::string& hostname, uint16_t port,
: stream_(nullptr),
maxBuffSizePool_(maxBuffSizePool),
inetAddress_(port, hostname.c_str()),
+ endpoint_(hostname + ":" + std::to_string(port)),
timeout_(waitSeconds) {}
void TcpConn::connect() {
@@ -143,9 +145,7 @@ void TcpConn::connect() {
ACE_OS::signal(SIGPIPE, SIG_IGN); // Ignore broken pipe
- LOGFINER(std::string("Connecting plain socket stream to ") +
- inetAddress_.get_host_name() + ":" +
- std::to_string(inetAddress_.get_port_number()) + " waiting " +
+ LOGFINER("Connecting plain socket stream to " + endpoint_ + " waiting " +
to_string(timeout_));
const ACE_Time_Value aceTimeout(timeout_);
diff --git a/cppcache/src/TcpConn.hpp b/cppcache/src/TcpConn.hpp
index 3a3295a..ed7d406 100644
--- a/cppcache/src/TcpConn.hpp
+++ b/cppcache/src/TcpConn.hpp
@@ -49,6 +49,7 @@ class TcpConn : public Connector {
protected:
ACE_INET_Addr inetAddress_;
+ std::string endpoint_;
std::chrono::microseconds timeout_;
static const size_t kChunkSize;