THRIFT-1563 thrift: make serve() throw an exception if it fails
authorRoger Meier <roger@apache.org>
Wed, 11 Apr 2012 21:48:56 +0000 (21:48 +0000)
committerRoger Meier <roger@apache.org>
Wed, 11 Apr 2012 21:48:56 +0000 (21:48 +0000)
Patch: Dave Watson

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1325026 13f79535-47bb-0310-9956-ffa450edef68

lib/cpp/src/server/TNonblockingServer.cpp
lib/cpp/src/server/TSimpleServer.cpp
lib/cpp/src/server/TThreadPoolServer.cpp
lib/cpp/src/server/TThreadedServer.cpp
lib/cpp/src/transport/TServerSocket.cpp

index 1ade895..bd76cfc 100644 (file)
@@ -1024,9 +1024,8 @@ void TNonblockingServer::createAndListenOnSocket() {
   // Wildcard address
   error = getaddrinfo(NULL, port, &hints, &res0);
   if (error) {
-    string errStr = "TNonblockingServer::serve() getaddrinfo " + string(gai_strerror(error));
-    GlobalOutput(errStr.c_str());
-    return;
+    throw TException("TNonblockingServer::serve() getaddrinfo " +
+                     string(gai_strerror(error)));
   }
 
   // Pick the ipv6 address first since ipv4 addresses can be mapped
@@ -1061,7 +1060,9 @@ void TNonblockingServer::createAndListenOnSocket() {
   if (::bind(s, res->ai_addr, res->ai_addrlen) == -1) {
     ::close(s);
     freeaddrinfo(res0);
-    throw TException("TNonblockingServer::serve() bind");
+    throw TTransportException(TTransportException::NOT_OPEN,
+                              "TNonblockingServer::serve() bind",
+                              errno);
   }
 
   // Done with the addr info
index 5def0e4..344945b 100644 (file)
@@ -42,14 +42,8 @@ void TSimpleServer::serve() {
   shared_ptr<TProtocol> inputProtocol;
   shared_ptr<TProtocol> outputProtocol;
 
-  try {
-    // Start the server listening
-    serverTransport_->listen();
-  } catch (TTransportException& ttx) {
-    string errStr = string("TSimpleServer::run() listen(): ") + ttx.what();
-    GlobalOutput(errStr.c_str());
-    return;
-  }
+  // Start the server listening
+  serverTransport_->listen();
 
   // Run the preServe event
   if (eventHandler_ != NULL) {
index ec30d76..fe58ff3 100644 (file)
@@ -121,14 +121,8 @@ void TThreadPoolServer::serve() {
   shared_ptr<TProtocol> inputProtocol;
   shared_ptr<TProtocol> outputProtocol;
 
-  try {
-    // Start the server listening
-    serverTransport_->listen();
-  } catch (TTransportException& ttx) {
-    string errStr = string("TThreadPoolServer::run() listen(): ") + ttx.what();
-    GlobalOutput(errStr.c_str());
-    return;
-  }
+  // Start the server listening
+  serverTransport_->listen();
 
   // Run the preServe event
   if (eventHandler_ != NULL) {
index 6b816a4..e99a909 100644 (file)
@@ -139,14 +139,8 @@ void TThreadedServer::serve() {
   shared_ptr<TProtocol> inputProtocol;
   shared_ptr<TProtocol> outputProtocol;
 
-  try {
-    // Start the server listening
-    serverTransport_->listen();
-  } catch (TTransportException& ttx) {
-    string errStr = string("TThreadedServer::run() listen(): ") +ttx.what();
-    GlobalOutput(errStr.c_str());
-    return;
-  }
+  // Start the server listening
+  serverTransport_->listen();
 
   // Run the preServe event
   if (eventHandler_ != NULL) {
index ec7a382..edc2cb8 100644 (file)
@@ -342,7 +342,8 @@ void TServerSocket::listen() {
     }
     GlobalOutput(errbuf);
     close();
-    throw TTransportException(TTransportException::NOT_OPEN, "Could not bind");
+    throw TTransportException(TTransportException::NOT_OPEN, "Could not bind",
+                              errno);
   }
 
   // Call listen