From 7859a579db3d0a4d2d4ca62993ee98e90dc9d617 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Thu, 31 May 2007 01:33:07 +0000 Subject: [PATCH] -- handle EINTRS in accept() Summary: - I love unix. Reviewed By: mcslee Test Plan: boz will test it git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665125 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/transport/TServerSocket.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp index e942a67f1..22346bddb 100644 --- a/lib/cpp/src/transport/TServerSocket.cpp +++ b/lib/cpp/src/transport/TServerSocket.cpp @@ -169,6 +169,9 @@ shared_ptr TServerSocket::acceptImpl() { fd_set fds; + int maxEintrs = 5; + int numEintrs = 0; + while (true) { FD_ZERO(&fds); FD_SET(serverSocket_, &fds); @@ -178,6 +181,12 @@ shared_ptr TServerSocket::acceptImpl() { int ret = select(serverSocket_+1, &fds, NULL, NULL, NULL); if (ret < 0) { + // error cases + if (error == EINTR && (numEintrs++ < maxEintrs)) { + // EINTR needs to be handled manually and we can tolerate + // a certain number + continue; + } perror("TServerSocket::acceptImpl() select -1"); throw TTransportException(TTransportException::UNKNOWN); } else if (ret > 0) { @@ -228,7 +237,7 @@ shared_ptr TServerSocket::acceptImpl() { if (recvTimeout_ > 0) { client->setRecvTimeout(recvTimeout_); } - + return client; }