THRIFT-4559: TSSLSocket no longer prints incorrect error for SYSCALL (#1549)

Client: cpp
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
index 7071698..251ef2f 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
@@ -403,11 +403,16 @@
       break;
     }
     unsigned int waitEventReturn;
+    bool breakout = false;
     switch (error) {
       case SSL_ERROR_ZERO_RETURN:
         throw TTransportException(TTransportException::END_OF_FILE, "client disconnected");
 
       case SSL_ERROR_SYSCALL:
+        if (errno_copy == 0 && ERR_peek_error() == 0) {
+          breakout = true;
+          break;
+        }
         if ((errno_copy != THRIFT_EINTR)
             && (errno_copy != THRIFT_EAGAIN)) {
               break;
@@ -450,6 +455,9 @@
         throw TTransportException(TTransportException::INTERNAL_ERROR, "unkown waitForEvent return value");
       default:;// do nothing
     }
+    if (breakout) {
+      break;
+    }
     string errors;
     buildErrors(errors, errno_copy, error);
     throw TSSLException("SSL_read: " + errors);
@@ -1024,6 +1032,14 @@
   }
   if (sslerrno) {
     errors += " (SSL_error_code = " + to_string(sslerrno) + ")";
+    if (sslerrno == SSL_ERROR_SYSCALL) {
+      char buf[4096];
+      int err;
+      while ((err = ERR_get_error()) != 0) {
+        errors += " ";
+        errors += ERR_error_string(err, buf);
+      }
+    }
   }
 }