THRIFT-497. cpp: Fix TSocket::read and peek on Max OS
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@781626 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp
index 3395dab..f99a6ff 100644
--- a/lib/cpp/src/transport/TSocket.cpp
+++ b/lib/cpp/src/transport/TSocket.cpp
@@ -108,7 +108,7 @@
int r = recv(socket_, &buf, 1, MSG_PEEK);
if (r == -1) {
int errno_copy = errno;
- #ifdef __FreeBSD__
+ #if defined __FreeBSD__ || defined __MACH__
/* shigin:
* freebsd returns -1 and ECONNRESET if socket was closed by
* the other side
@@ -338,20 +338,22 @@
goto try_again;
}
- // Now it's not a try again case, but a real probblez
- GlobalOutput.perror("TSocket::read() recv() " + getSocketInfo(), errno_copy);
-
- // If we disconnect with no linger time
+ #if defined __FreeBSD__ || defined __MACH__
if (errno_copy == ECONNRESET) {
- #ifdef __FreeBSD__
/* shigin: freebsd doesn't follow POSIX semantic of recv and fails with
* ECONNRESET if peer performed shutdown
*/
close();
return 0;
- #else
+ }
+ #endif
+
+ // Now it's not a try again case, but a real probblez
+ GlobalOutput.perror("TSocket::read() recv() " + getSocketInfo(), errno_copy);
+
+ // If we disconnect with no linger time
+ if (errno_copy == ECONNRESET) {
throw TTransportException(TTransportException::NOT_OPEN, "ECONNRESET");
- #endif
}
// This ish isn't open