THRIFT: generic output handler

Summary: I'm tired of getting output from thrift via perror AND exceptions, so
this class allows the client to set an alternate (or empty) handler for error
output

Reviewed By: mcslee

Test Plan: I ran on the worker with the default, got output via perror, then
overloaded with my own function and got output via syslog and then NULL


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665131 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp
index 0777807..42364fa 100644
--- a/lib/cpp/src/transport/TSocket.cpp
+++ b/lib/cpp/src/transport/TSocket.cpp
@@ -96,7 +96,7 @@
   uint8_t buf;
   int r = recv(socket_, &buf, 1, MSG_PEEK);
   if (r == -1) {
-    perror("TSocket::peek()");
+    GlobalOutput("TSocket::peek()");
     close();
     throw TTransportException(TTransportException::UNKNOWN, "recv() ERROR:" + errno);
   }
@@ -111,7 +111,7 @@
   // Create socket
   socket_ = socket(AF_INET, SOCK_STREAM, 0);
   if (socket_ == -1) {
-    perror("TSocket::open() socket");
+    GlobalOutput("TSocket::open() socket");
     close();
     throw TTransportException(TTransportException::NOT_OPEN, "socket() ERROR:" + errno);
   }
@@ -143,7 +143,7 @@
     struct hostent *host_entry = gethostbyname(host_.c_str());
     
     if (host_entry == NULL) {
-      perror("TSocket: dns error: failed call to gethostbyname.");
+      GlobalOutput("TSocket: dns error: failed call to gethostbyname.");
       close();
       throw TTransportException(TTransportException::NOT_OPEN, "gethostbyname() failed");
     }
@@ -181,7 +181,7 @@
     close();
     char buff[1024];
     sprintf(buff, "TSocket::open() connect %s %d", host_.c_str(), port_);
-    perror(buff);
+    GlobalOutput(buff);
     throw TTransportException(TTransportException::NOT_OPEN, "open() ERROR: " + errno);
   }
 
@@ -198,22 +198,22 @@
     int ret2 = getsockopt(socket_, SOL_SOCKET, SO_ERROR, (void *)&val, &lon);
     if (ret2 == -1) {
       close();
-      perror("TSocket::open() getsockopt SO_ERROR");
+      GlobalOutput("TSocket::open() getsockopt SO_ERROR");
       throw TTransportException(TTransportException::NOT_OPEN, "open() ERROR: " + errno);
     }
     if (val == 0) {
       goto done;
     }
     close();
-    perror("TSocket::open() SO_ERROR was set");
+    GlobalOutput("TSocket::open() SO_ERROR was set");
     throw TTransportException(TTransportException::NOT_OPEN, "open() ERROR: " + errno);
   } else if (ret == 0) {
     close();
-    perror("TSocket::open() timeed out");
+    GlobalOutput("TSocket::open() timeed out");
     throw TTransportException(TTransportException::NOT_OPEN, "open() ERROR: " + errno);   
   } else {
     close();
-    perror("TSocket::open() select error");
+    GlobalOutput("TSocket::open() select error");
     throw TTransportException(TTransportException::NOT_OPEN, "open() ERROR: " + errno);
   }
 
@@ -285,7 +285,7 @@
     }
     
     // Now it's not a try again case, but a real probblez
-    perror("TSocket::read()");
+    GlobalOutput("TSocket::read()");
 
     // If we disconnect with no linger time
     if (errno == ECONNRESET) {
@@ -354,7 +354,7 @@
         throw TTransportException(TTransportException::NOT_OPEN, "ENOTCONN");
       }
 
-      perror("TSocket::write() send < 0");
+      GlobalOutput("TSocket::write() send < 0");
       throw TTransportException(TTransportException::UNKNOWN, "ERROR:" + errno);
     }
     
@@ -384,7 +384,7 @@
   struct linger l = {(lingerOn_ ? 1 : 0), lingerVal_};
   int ret = setsockopt(socket_, SOL_SOCKET, SO_LINGER, &l, sizeof(l));
   if (ret == -1) {
-    perror("TSocket::setLinger()");
+    GlobalOutput("TSocket::setLinger()");
   }
 }
 
@@ -398,7 +398,7 @@
   int v = noDelay_ ? 1 : 0;
   int ret = setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
   if (ret == -1) {
-    perror("TSocket::setNoDelay()");
+    GlobalOutput("TSocket::setNoDelay()");
   }
 }
 
@@ -418,7 +418,7 @@
   struct timeval r = recvTimeval_;
   int ret = setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, &r, sizeof(r));
   if (ret == -1) {
-    perror("TSocket::setRecvTimeout()");
+    GlobalOutput("TSocket::setRecvTimeout()");
   }
 }
 
@@ -432,7 +432,7 @@
                       (int)((sendTimeout_%1000)*1000)};
   int ret = setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, &s, sizeof(s));
   if (ret == -1) {
-    perror("TSocket::setSendTimeout()");
+    GlobalOutput("TSocket::setSendTimeout()");
   }
 }