diff options
author | Mario Emmenlauer <memmenlauer@biodataanalysis.de> | 2020-09-09 13:53:31 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2020-09-15 09:03:56 +0200 |
commit | 40cd0215f15ccbd2462bb855389467b0fd05b66a (patch) | |
tree | d55dc0da383d601fda508355de4f5cf5a5059470 | |
parent | 304f50b39fbb1f6a66c1bb76cf88a135d015fda9 (diff) | |
download | thrift-40cd0215f15ccbd2462bb855389467b0fd05b66a.tar.gz |
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
-rw-r--r-- | lib/cpp/src/thrift/transport/TSocket.cpp | 16 | ||||
-rw-r--r-- | 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 81aaccf43..5000baf44 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 043f0de8d..8a224f2de 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 |