Add a few utility methods and helpers to Thrift C++ Sockets
Summary: Submitted by Dave Simpson @ Powerset.
Reviewed By: mcslee
Test Plan: test/cpp
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665370 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TSocket.h b/lib/cpp/src/transport/TSocket.h
index 57ff127..f0495ec 100644
--- a/lib/cpp/src/transport/TSocket.h
+++ b/lib/cpp/src/transport/TSocket.h
@@ -13,7 +13,7 @@
#include "TTransport.h"
#include "TServerSocket.h"
-namespace facebook { namespace thrift { namespace transport {
+namespace facebook { namespace thrift { namespace transport {
/**
* TCP Socket implementation of the TTransport interface.
@@ -37,7 +37,7 @@
*
*/
TSocket();
-
+
/**
* Constructs a new socket. Note that this does NOT actually connect the
* socket.
@@ -126,7 +126,7 @@
* Whether to enable/disable Nagle's algorithm.
*
* @param noDelay Whether or not to disable the algorithm.
- * @return
+ * @return
*/
void setNoDelay(bool noDelay);
@@ -151,9 +151,27 @@
*/
void setMaxRecvRetries(int maxRecvRetries);
- /** get socket information */
+ /**
+ * Get socket information formated as a string <Host: x Port: x>
+ */
std::string getSocketInfo();
+ /**
+ * Returns the DNS name of the host to which the socket is connected
+ */
+ std::string getPeerHost();
+
+ /**
+ * Returns the address of the host to which the socket is connected
+ */
+ std::string getPeerAddress();
+
+ /**
+ * Returns the port of the host to which the socket is connected
+ **/
+ int getPeerPort();
+
+
protected:
/**
* Constructor to create socket from raw UNIX handle. Never called directly
@@ -167,6 +185,15 @@
/** Host to connect to */
std::string host_;
+ /** Peer hostname */
+ std::string peerHost_;
+
+ /** Peer address */
+ std::string peerAddress_;
+
+ /** Peer port */
+ int peerPort_;
+
/** Port number to connect on */
int port_;
@@ -184,7 +211,7 @@
/** Linger on */
bool lingerOn_;
-
+
/** Linger val */
int lingerVal_;