From ebc99e0e164e0ffc2053f3379d384719ff47cb6e Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Mon, 15 Jan 2007 23:14:58 +0000 Subject: [PATCH] -- Allow manual setting of host and port in TSocket Summary: -- required for TSocketPool equivalent functionality Reviewed By: slee Notes: -- Todo is to replicate TSocketPool.php in C++ git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664912 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/transport/TSocket.cpp | 22 ++++++++++++++++++++++ lib/cpp/src/transport/TSocket.h | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp index 8b9048c8..e3615caf 100644 --- a/lib/cpp/src/transport/TSocket.cpp +++ b/lib/cpp/src/transport/TSocket.cpp @@ -47,6 +47,20 @@ TSocket::TSocket(string host, int port) : recvTimeval_.tv_usec = (int)((recvTimeout_%1000)*1000); } +TSocket::TSocket() : + host_(""), + port_(0), + socket_(0), + connTimeout_(0), + sendTimeout_(0), + recvTimeout_(0), + lingerOn_(1), + lingerVal_(0), + noDelay_(1) { + recvTimeval_.tv_sec = (int)(recvTimeout_/1000); + recvTimeval_.tv_usec = (int)((recvTimeout_%1000)*1000); +} + TSocket::TSocket(int socket) : host_(""), port_(0), @@ -306,6 +320,14 @@ void TSocket::write(const uint8_t* buf, uint32_t len) { } } +void TSocket::setHost(string host) { + host_ = host; +} + +void TSocket::setPort(int port) { + port_ = port; +} + void TSocket::setLinger(bool on, int linger) { lingerOn_ = on; lingerVal_ = linger; diff --git a/lib/cpp/src/transport/TSocket.h b/lib/cpp/src/transport/TSocket.h index 8137984a..3decb2cf 100644 --- a/lib/cpp/src/transport/TSocket.h +++ b/lib/cpp/src/transport/TSocket.h @@ -24,6 +24,13 @@ class TSocket : public TTransport { friend class TServerSocket; public: + /** + * Constructs a new socket. Note that this does NOT actually connect the + * socket. + * + */ + TSocket(); + /** * Constructs a new socket. Note that this does NOT actually connect the * socket. @@ -33,6 +40,7 @@ class TSocket : public TTransport { */ TSocket(std::string host, int port); + /** * Destroyes the socket object, closing it if necessary. */ @@ -72,6 +80,20 @@ class TSocket : public TTransport { */ void write(const uint8_t* buf, uint32_t len); + /** + * Set the host that socket will connect to + * + * @param host host identifier + */ + void setHost(std::string host); + + /** + * Set the port that socket will connect to + * + * @param port port number + */ + void setPort(int port); + /** * Controls whether the linger option is set on the socket. * -- 2.17.1