]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1542] Convert the rcodes to exceptions
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 26 Jan 2012 15:35:23 +0000 (16:35 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 26 Jan 2012 15:35:23 +0000 (16:35 +0100)
So we can distinguish the errors.

src/lib/server_common/socket_request.cc
src/lib/server_common/socket_request.h
src/lib/server_common/tests/socket_requestor_test.cc

index 5b71ab2640d740706134771bd70ddf1178069f41..bc4b984ac08084592127776d4e152da5e583c7c8 100644 (file)
@@ -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());
index 7398ee7d84bf18c411b96f38c54e7efc399496ba..ea22fa6036f98d295f24d10ad6de6d643389fe57 100644 (file)
@@ -143,6 +143,7 @@ public:
     /// 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)
         { }
index fc5b3038e527b1e0ffe1b719b97625bd4ca6e329..e917e0cb4cba11730cc64c478886a85abeff62f0 100644 (file)
@@ -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