Thrift: Supported for file descriptor == 0 and cleanup error output
Summary:
Thrift improperly initialized file descriptors to zero and treated 0 and an invalid value. 0 is a valid file descriptor. Also, commented out error message on client disconnect for TThreadPoolServer
Reviewed By: Marc & Karl
Revert Plan: revertible
Notes:
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664972 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp
index 1407b8c..8514d18 100644
--- a/lib/cpp/src/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/server/TThreadPoolServer.cpp
@@ -34,7 +34,9 @@
}
}
} catch (TTransportException& ttx) {
- cerr << "TThreadPoolServer client died: " << ttx.what() << endl;
+ // This is reasonably expected, client didn't send a full request so just
+ // ignore him
+ //cerr << "TThreadPoolServer client died: " << ttx.what() << endl;
} catch (TException& x) {
cerr << "TThreadPoolServer exception: " << x.what() << endl;
} catch (...) {
diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp
index f9f3e7f..8d5e5e4 100644
--- a/lib/cpp/src/transport/TServerSocket.cpp
+++ b/lib/cpp/src/transport/TServerSocket.cpp
@@ -13,14 +13,14 @@
TServerSocket::TServerSocket(int port) :
port_(port),
- serverSocket_(0),
+ serverSocket_(-1),
acceptBacklog_(1024),
sendTimeout_(0),
recvTimeout_(0) {}
TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout) :
port_(port),
- serverSocket_(0),
+ serverSocket_(-1),
acceptBacklog_(1024),
sendTimeout_(sendTimeout),
recvTimeout_(recvTimeout) {}
@@ -116,7 +116,7 @@
(struct sockaddr *) &clientAddress,
(socklen_t *) &size);
- if (clientSocket <= 0) {
+ if (clientSocket < 0) {
perror("TServerSocket::accept()");
throw TTransportException(TTX_UNKNOWN, "ERROR:" + errno);
}
@@ -132,11 +132,11 @@
}
void TServerSocket::close() {
- if (serverSocket_ > 0) {
+ if (serverSocket_ >= 0) {
shutdown(serverSocket_, SHUT_RDWR);
::close(serverSocket_);
}
- serverSocket_ = 0;
+ serverSocket_ = -1;
}
}}} // facebook::thrift::transport
diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp
index 0c3f773..9df78a1 100644
--- a/lib/cpp/src/transport/TSocket.cpp
+++ b/lib/cpp/src/transport/TSocket.cpp
@@ -36,7 +36,7 @@
TSocket::TSocket(string host, int port) :
host_(host),
port_(port),
- socket_(0),
+ socket_(-1),
connTimeout_(0),
sendTimeout_(0),
recvTimeout_(0),
@@ -50,7 +50,7 @@
TSocket::TSocket() :
host_(""),
port_(0),
- socket_(0),
+ socket_(-1),
connTimeout_(0),
sendTimeout_(0),
recvTimeout_(0),
@@ -80,7 +80,7 @@
}
bool TSocket::isOpen() {
- return (socket_ > 0);
+ return (socket_ >= 0);
}
bool TSocket::peek() {
@@ -209,15 +209,15 @@
}
void TSocket::close() {
- if (socket_ > 0) {
+ if (socket_ >= 0) {
shutdown(socket_, SHUT_RDWR);
::close(socket_);
}
- socket_ = 0;
+ socket_ = -1;
}
uint32_t TSocket::read(uint8_t* buf, uint32_t len) {
- if (socket_ <= 0) {
+ if (socket_ < 0) {
throw TTransportException(TTX_NOT_OPEN, "Called read on non-open socket");
}
@@ -274,7 +274,7 @@
}
void TSocket::write(const uint8_t* buf, uint32_t len) {
- if (socket_ <= 0) {
+ if (socket_ < 0) {
throw TTransportException(TTX_NOT_OPEN, "Called write on non-open socket");
}
@@ -332,7 +332,7 @@
void TSocket::setLinger(bool on, int linger) {
lingerOn_ = on;
lingerVal_ = linger;
- if (socket_ <= 0) {
+ if (socket_ < 0) {
return;
}
@@ -345,7 +345,7 @@
void TSocket::setNoDelay(bool noDelay) {
noDelay_ = noDelay;
- if (socket_ <= 0) {
+ if (socket_ < 0) {
return;
}
@@ -365,7 +365,7 @@
recvTimeout_ = ms;
recvTimeval_.tv_sec = (int)(recvTimeout_/1000);
recvTimeval_.tv_usec = (int)((recvTimeout_%1000)*1000);
- if (socket_ <= 0) {
+ if (socket_ < 0) {
return;
}
@@ -379,7 +379,7 @@
void TSocket::setSendTimeout(int ms) {
sendTimeout_ = ms;
- if (socket_ <= 0) {
+ if (socket_ < 0) {
return;
}