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.cpp b/lib/cpp/src/Thrift.cpp
index 88890d4..963f938 100644
--- a/lib/cpp/src/Thrift.cpp
+++ b/lib/cpp/src/Thrift.cpp
@@ -11,6 +11,31 @@
TOutput GlobalOutput;
+std::string TOutput::strerror_s(int errno_copy) {
+#ifndef HAVE_STRERROR_R
+ return "errno = " + lexical_cast<string>(errno_copy);
+#else // HAVE_STRERROR_R
+
+ char b_errbuf[1024] = { '\0' };
+#ifdef STRERROR_R_CHAR_P
+ char *b_error = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf));
+#else
+ char *b_error = b_errbuf;
+ int rv = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf));
+ if (rv == -1) {
+ // strerror_r failed. omgwtfbbq.
+ return "XSI-compliant strerror_r() failed with errno = " +
+ lexical_cast<string>(errno_copy);
+ }
+#endif
+ // Can anyone prove that explicit cast is probably not necessary
+ // to ensure that the string object is constructed before
+ // b_error becomes invalid?
+ return std::string(b_error);
+
+#endif // HAVE_STRERROR_R
+}
+
uint32_t TApplicationException::read(facebook::thrift::protocol::TProtocol* iprot) {
uint32_t xfer = 0;
std::string fname;