Server robustness fixes in Thrift C++ libs
Summary: ServerSockets can be interrupt() ed
Reviewed By: marc, karl
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665039 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp
index 5d653c4..95781f0 100644
--- a/lib/cpp/src/transport/TSocket.cpp
+++ b/lib/cpp/src/transport/TSocket.cpp
@@ -157,9 +157,13 @@
// Set the socket to be non blocking for connect if a timeout exists
int flags = fcntl(socket_, F_GETFL, 0);
if (connTimeout_ > 0) {
- fcntl(socket_, F_SETFL, flags | O_NONBLOCK);
+ if (-1 == fcntl(socket_, F_SETFL, flags | O_NONBLOCK)) {
+ throw TTransportException(TTransportException::NOT_OPEN, "fcntl() failed");
+ }
} else {
- fcntl(socket_, F_SETFL, flags | ~O_NONBLOCK);
+ if (-1 == fcntl(socket_, F_SETFL, flags & ~O_NONBLOCK)) {
+ throw TTransportException(TTransportException::NOT_OPEN, "fcntl() failed");
+ }
}
// Conn timeout