BIND 10 trac1542, updated. 28cd9c1145fd52f2729f1f9f4d28c263ca2cc0d4 [1542] Convert the rcodes to exceptions

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jan 26 15:35:58 UTC 2012


The branch, trac1542 has been updated
       via  28cd9c1145fd52f2729f1f9f4d28c263ca2cc0d4 (commit)
       via  5d3ea6cbda70b4ffeb278fdd8aa3c3a84750e580 (commit)
       via  efcff547c56719305bc35186683b450ea759d684 (commit)
      from  67b1031ec37365288502d0894cccddec7e12657e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 28cd9c1145fd52f2729f1f9f4d28c263ca2cc0d4
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jan 26 16:35:23 2012 +0100

    [1542] Convert the rcodes to exceptions
    
    So we can distinguish the errors.

commit 5d3ea6cbda70b4ffeb278fdd8aa3c3a84750e580
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jan 26 16:20:27 2012 +0100

    [1542] Define the exceptions

commit efcff547c56719305bc35186683b450ea759d684
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jan 26 15:51:47 2012 +0100

    [1542] Different rcodes for expected exceptions

-----------------------------------------------------------------------

Summary of changes:
 src/bin/bind10/bind10_src.py.in                    |    4 ++
 src/bin/bind10/tests/bind10_test.py.in             |    7 +++
 src/lib/server_common/socket_request.cc            |    8 ++++
 src/lib/server_common/socket_request.h             |   45 ++++++++++++++++++++
 .../server_common/tests/socket_requestor_test.cc   |    6 +++
 5 files changed, 70 insertions(+), 0 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index 3e14f0f..35ef680 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -805,6 +805,10 @@ class BoB:
                 'token': token,
                 'path': self._socket_path
             })
+        except isc.bind10.socket_cache.SocketError as e:
+            return isc.config.ccsession.create_answer(2, str(e))
+        except isc.bind10.socket_cache.ShareError as e:
+            return isc.config.ccsession.create_answer(3, str(e))
         except Exception as e:
             return isc.config.ccsession.create_answer(1, str(e))
 
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index 63e1446..4771cad 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -296,6 +296,13 @@ class TestCacheCommands(unittest.TestCase):
         # to an error, not propagated
         self.__raise_exception = Exception("Test exception")
         check_code(1, self.__socket_args)
+        # The special "expected" exceptions
+        self.__raise_exception = \
+            isc.bind10.socket_cache.ShareError("Not shared")
+        check_code(3, self.__socket_args)
+        self.__raise_exception = \
+            isc.bind10.socket_cache.SocketError("Not shared", 13)
+        check_code(2, self.__socket_args)
 
     def drop_socket(self, token):
         """
diff --git a/src/lib/server_common/socket_request.cc b/src/lib/server_common/socket_request.cc
index 5b71ab2..bc4b984 100644
--- a/src/lib/server_common/socket_request.cc
+++ b/src/lib/server_common/socket_request.cc
@@ -133,6 +133,14 @@ readRequestSocketAnswer(isc::data::ConstElementPtr recv_msg,
     int rcode;
     isc::data::ConstElementPtr answer = isc::config::parseAnswer(rcode,
                                                                  recv_msg);
+    // Translate known rcodes to the corresponding exceptions
+    if (rcode == 2) {
+        isc_throw(SocketRequestor::SocketAllocateError, answer->str());
+    }
+    if (rcode == 3) {
+        isc_throw(SocketRequestor::ShareError, answer->str());
+    }
+    // The unknown exceptions
     if (rcode != 0) {
         isc_throw(isc::config::CCSessionError,
                   "Error response when requesting socket: " << answer->str());
diff --git a/src/lib/server_common/socket_request.h b/src/lib/server_common/socket_request.h
index b67c66a..ea22fa6 100644
--- a/src/lib/server_common/socket_request.h
+++ b/src/lib/server_common/socket_request.h
@@ -104,6 +104,51 @@ public:
         { }
     };
 
+    /// \brief Exception when we can't return a requested socket, but we're
+    ///     sure we could return others
+    ///
+    /// This is thrown if the requested socket can't be granted, but it is only
+    /// that one socket, not that the system would be broken or anything. This
+    /// exception is a common base class for the concrete exceptions actually
+    /// thrown.
+    ///
+    /// \see ShareError
+    /// \see SocketAllocateError
+    class NonFatalSocketError : public SocketError {
+    public:
+        NonFatalSocketError(const char* file, size_t line, const char* what) :
+            SocketError(file, line, what)
+        { }
+    };
+
+    /// \brief Exception when the socke is allocated by other bind10 module
+    ///    and it doesn't want to share it.
+    ///
+    /// This is thrown if a socket is requested and the socket is already
+    /// allocated by bind10, but other bind10 module(s) is using it and
+    /// the sharing parameters are incompatible (the socket can't be shared
+    /// between the module and our module).
+    class ShareError : public NonFatalSocketError {
+    public:
+        ShareError(const char* file, size_t line, const char* what) :
+            NonFatalSocketError(file, line, what)
+        { }
+    };
+
+    /// \brief Exception when the operation system doesn't allow us to create
+    ///    the requested socket.
+    ///
+    /// This happens when the socket() or bind() call fails in the socket
+    /// creator. This can happen when the address/port pair is already taken
+    /// by a different application, the socket creator doesn't have enough
+    /// privileges, or for some kind of similar reason.
+    class SocketAllocateError : public NonFatalSocketError {
+    public:
+        SocketAllocateError(const char* file, size_t line, const char* what) :
+            NonFatalSocketError(file, line, what)
+        { }
+    };
+
     /// \brief Ask for a socket
     ///
     /// Asks the socket creator to give us a socket. The socket will be bound
diff --git a/src/lib/server_common/tests/socket_requestor_test.cc b/src/lib/server_common/tests/socket_requestor_test.cc
index fc5b303..e917e0c 100644
--- a/src/lib/server_common/tests/socket_requestor_test.cc
+++ b/src/lib/server_common/tests/socket_requestor_test.cc
@@ -250,8 +250,14 @@ TEST_F(SocketRequestorTest, testBadRequestAnswers) {
     }
 
     // Send back an error response
+    // A generic one first
     session.getMessages()->add(createAnswer(1, "error"));
     ASSERT_THROW(doRequest(), CCSessionError);
+    // Now some with specific exceptions
+    session.getMessages()->add(createAnswer(2, "error"));
+    ASSERT_THROW(doRequest(), SocketRequestor::SocketAllocateError);
+    session.getMessages()->add(createAnswer(3, "error"));
+    ASSERT_THROW(doRequest(), SocketRequestor::ShareError);
 }
 
 // Helper function to create the release commands as we expect




More information about the bind10-changes mailing list