Browse Source

[805] Some exception handling

Catch on the closing bracket, include little bit more in the try.
Michal 'vorner' Vaner 13 years ago
parent
commit
5e04e03abd
2 changed files with 9 additions and 14 deletions
  1. 4 5
      src/lib/asiodns/tcp_server.cc
  2. 5 9
      src/lib/asiodns/udp_server.cc

+ 4 - 5
src/lib/asiodns/tcp_server.cc

@@ -83,14 +83,13 @@ TCPServer::TCPServer(io_service& io_service, int fd, int af,
     }
     LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_TCP).arg(fd);
 
-    acceptor_.reset(new tcp::acceptor(io_service));
     try {
+        acceptor_.reset(new tcp::acceptor(io_service));
         acceptor_->assign(af == AF_INET6 ? tcp::v6() : tcp::v4(), fd);
         acceptor_->listen();
-    }
-    // Whatever the thing throws, it is something from ASIO and we convert
-    // it
-    catch (const std::exception& exception) {
+    } catch (const std::exception& exception) {
+        // Whatever the thing throws, it is something from ASIO and we convert
+        // it
         isc_throw(IOError, exception.what());
     }
 }

+ 5 - 9
src/lib/asiodns/udp_server.cc

@@ -86,16 +86,12 @@ struct UDPServer::Data {
                       "or AF_INET6, not " << af);
         }
         LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_UDP).arg(fd);
-        // We must use different instantiations for v4 and v6;
-        // otherwise ASIO will bind to both
-        udp proto = af == AF_INET6 ? udp::v6() : udp::v4();
-        socket_.reset(new udp::socket(io_service));
         try {
-            socket_->assign(proto, fd);
-        }
-        // Whatever the thing throws, it is something from ASIO and we convert
-        // it
-        catch (const std::exception& exception) {
+            socket_.reset(new udp::socket(io_service));
+            socket_->assign(AF_INET6 ? udp::v6() : udp::v4(), fd);
+        } catch (const std::exception& exception) {
+            // Whatever the thing throws, it is something from ASIO and we convert
+            // it
             isc_throw(IOError, exception.what());
         }
     }