diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp index 8a14ea5cd..f9f3e7fa0 100644 --- a/lib/cpp/src/transport/TServerSocket.cpp +++ b/lib/cpp/src/transport/TServerSocket.cpp @@ -106,7 +106,7 @@ void TServerSocket::listen() { } shared_ptr TServerSocket::acceptImpl() { - if (serverSocket_ <= 0) { + if (serverSocket_ < 0) { throw TTransportException(TTX_NOT_OPEN, "TServerSocket not listening"); } @@ -120,7 +120,7 @@ shared_ptr TServerSocket::acceptImpl() { perror("TServerSocket::accept()"); throw TTransportException(TTX_UNKNOWN, "ERROR:" + errno); } - + shared_ptr client(new TSocket(clientSocket)); if (sendTimeout_ > 0) { client->setSendTimeout(sendTimeout_); diff --git a/lib/cpp/src/transport/TTransportException.h b/lib/cpp/src/transport/TTransportException.h index de94a7c9b..6dbfb13bc 100644 --- a/lib/cpp/src/transport/TTransportException.h +++ b/lib/cpp/src/transport/TTransportException.h @@ -1,6 +1,7 @@ #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ #define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1 +#include #include namespace facebook { namespace thrift { namespace transport { @@ -53,6 +54,15 @@ class TTransportException : public facebook::thrift::TException { TTransportExceptionType getType() { return type_; } + + virtual const char* what() const throw() { + if (message_.empty()) { + return (std::string("Default Transport Exception: ") + + boost::lexical_cast(type_)).c_str(); + } else { + return message_.c_str(); + } + } protected: /** Error code */