You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/09/15 07:04:22 UTC
[thrift] branch master updated: Added getter and setter for domain
socket path,
and minor fix for printing abstract domain socket paths Client: cpp Patch:
Mario Emmenlauer
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 40cd021 Added getter and setter for domain socket path, and minor fix for printing abstract domain socket paths Client: cpp Patch: Mario Emmenlauer
40cd021 is described below
commit 40cd0215f15ccbd2462bb855389467b0fd05b66a
Author: Mario Emmenlauer <me...@biodataanalysis.de>
AuthorDate: Wed Sep 9 13:53:31 2020 +0200
Added getter and setter for domain socket path, and minor fix for printing abstract domain socket paths
Client: cpp
Patch: Mario Emmenlauer
This closes #2233
---
lib/cpp/src/thrift/transport/TSocket.cpp | 16 ++++++++++++++--
lib/cpp/src/thrift/transport/TSocket.h | 15 +++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp
index 81aaccf..5000baf 100644
--- a/lib/cpp/src/thrift/transport/TSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSocket.cpp
@@ -438,7 +438,7 @@ void TSocket::open() {
void TSocket::unix_open() {
if (!path_.empty()) {
- // Unix Domain SOcket does not need addrinfo struct, so we pass nullptr
+ // Unix Domain Socket does not need addrinfo struct, so we pass NULL
openConnection(nullptr);
}
}
@@ -711,6 +711,10 @@ int TSocket::getPort() {
return port_;
}
+std::string TSocket::getPath() {
+ return path_;
+}
+
void TSocket::setHost(string host) {
host_ = host;
}
@@ -719,6 +723,10 @@ void TSocket::setPort(int port) {
port_ = port;
}
+void TSocket::setPath(std::string path) {
+ path_ = path;
+}
+
void TSocket::setLinger(bool on, int linger) {
lingerOn_ = on;
lingerVal_ = linger;
@@ -828,7 +836,11 @@ string TSocket::getSocketInfo() const {
oss << "<Host: " << host_ << " Port: " << port_ << ">";
}
} else {
- oss << "<Path: " << path_ << ">";
+ std::string fmt_path_ = path_;
+ // Handle printing abstract sockets (first character is a '\0' char):
+ if (!fmt_path_.empty() && fmt_path_[0] == '\0')
+ fmt_path_[0] = '@';
+ oss << "<Path: " << fmt_path_ << ">";
}
return oss.str();
}
diff --git a/lib/cpp/src/thrift/transport/TSocket.h b/lib/cpp/src/thrift/transport/TSocket.h
index 043f0de..8a224f2 100644
--- a/lib/cpp/src/thrift/transport/TSocket.h
+++ b/lib/cpp/src/thrift/transport/TSocket.h
@@ -68,6 +68,7 @@ public:
* Note that this does NOT actually connect the socket.
*
* @param path The Unix domain socket e.g. "/tmp/ThriftTest.binary.thrift"
+ * or a zero-prefixed string to create an abstract domain socket on Linux.
*/
TSocket(const std::string& path, std::shared_ptr<TConfiguration> config = nullptr);
@@ -150,6 +151,13 @@ public:
int getPort();
/**
+ * Get the Unix domain socket path that the socket is connected to
+ *
+ * @return std::string path
+ */
+ std::string getPath();
+
+ /**
* Set the host that socket will connect to
*
* @param host host identifier
@@ -164,6 +172,13 @@ public:
void setPort(int port);
/**
+ * Set the Unix domain socket path for the socket
+ *
+ * @param path std::string path
+ */
+ void setPath(std::string path);
+
+ /**
* Controls whether the linger option is set on the socket.
*
* @param on Whether SO_LINGER is on