THRIFT-1335: Add accept timeout to TServerSocket
Client: cpp
Patch: Dave Watson

Added an accept timeout to the TServerSocket poll loop



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1170443 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp
index 82516ff..efe08fe 100644
--- a/lib/cpp/src/transport/TServerSocket.cpp
+++ b/lib/cpp/src/transport/TServerSocket.cpp
@@ -63,6 +63,7 @@
   acceptBacklog_(1024),
   sendTimeout_(0),
   recvTimeout_(0),
+  accTimeout_(-1),
   retryLimit_(0),
   retryDelay_(0),
   tcpSendBuffer_(0),
@@ -76,6 +77,7 @@
   acceptBacklog_(1024),
   sendTimeout_(sendTimeout),
   recvTimeout_(recvTimeout),
+  accTimeout_(-1),
   retryLimit_(0),
   retryDelay_(0),
   tcpSendBuffer_(0),
@@ -109,6 +111,10 @@
   recvTimeout_ = recvTimeout;
 }
 
+void TServerSocket::setAcceptTimeout(int accTimeout) {
+  accTimeout_ = accTimeout;
+}
+
 void TServerSocket::setRetryLimit(int retryLimit) {
   retryLimit_ = retryLimit;
 }
@@ -342,7 +348,11 @@
       fds[1].fd = intSock2_;
       fds[1].events = POLLIN;
     }
-    int ret = poll(fds, 2, -1);
+    /*
+      TODO: if EINTR is received, we'll restart the timeout.
+      To be accurate, we need to fix this in the future.
+     */
+    int ret = poll(fds, 2, accTimeout_);
 
     if (ret < 0) {
       // error cases
diff --git a/lib/cpp/src/transport/TServerSocket.h b/lib/cpp/src/transport/TServerSocket.h
index 40a1148..280ee69 100644
--- a/lib/cpp/src/transport/TServerSocket.h
+++ b/lib/cpp/src/transport/TServerSocket.h
@@ -43,6 +43,8 @@
   void setSendTimeout(int sendTimeout);
   void setRecvTimeout(int recvTimeout);
 
+  void setAcceptTimeout(int accTimeout);
+
   void setRetryLimit(int retryLimit);
   void setRetryDelay(int retryDelay);
 
@@ -65,6 +67,7 @@
   int acceptBacklog_;
   int sendTimeout_;
   int recvTimeout_;
+  int accTimeout_;
   int retryLimit_;
   int retryDelay_;
   int tcpSendBuffer_;