Thrift error logging improvements

Summary: - Move strerror_s to Thrift.h (was previously in TTransportException.h)
         - Capture errno as soon as syscall returns failure and make it part of error message.
         - Cleaned up several instances of the wrong error value being printed.
         - More consistently pass the errno in the TTransport Exception
         - Add more consistent error logging for the various transport failure modes

Reviewed By: dreiss

Test Plan: - compile everything.
           - test on search tier

Revert: OK

TracCamp Project: Thrift

DiffCamp Revision: 11077


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665648 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/Thrift.h b/lib/cpp/src/Thrift.h
index 8e93bb0..6eb20bb 100644
--- a/lib/cpp/src/Thrift.h
+++ b/lib/cpp/src/Thrift.h
@@ -21,6 +21,8 @@
 #include <set>
 #include <vector>
 #include <exception>
+#include <string>
+#include <boost/lexical_cast.hpp>
 
 #include "TLogging.h"
 
@@ -28,7 +30,7 @@
 
 class TOutput {
  public:
-  TOutput() : f_(&perrorTimeWrapper) {}
+  TOutput() : f_(&errorTimeWrapper) {}
 
   inline void setOutputFunction(void (*function)(const char *)){
     f_ = function;
@@ -38,15 +40,18 @@
     f_(message);
   }
 
-  inline static void perrorTimeWrapper(const char* msg) {
+  inline static void errorTimeWrapper(const char* msg) {
     time_t now;
     char dbgtime[25];
     time(&now);
     ctime_r(&now, dbgtime);
     dbgtime[24] = 0;
-    fprintf(stderr, "%s ", dbgtime);
-    perror(msg);
+    fprintf(stderr, "Thrift: %s %s\n", dbgtime, msg);
   }
+
+  /** Just like strerror_r but returns a C++ string object. */
+  static std::string strerror_s(int errno_copy);
+
  private:
   void (*f_)(const char *);
 };