]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3970] Moved WatchSocket class to utilities.
authorMarcin Siodelski <marcin@isc.org>
Fri, 21 Aug 2015 19:41:34 +0000 (21:41 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 21 Aug 2015 19:41:34 +0000 (21:41 +0200)
12 files changed:
src/lib/dhcp_ddns/Makefile.am
src/lib/dhcp_ddns/ncr_udp.cc
src/lib/dhcp_ddns/ncr_udp.h
src/lib/dhcp_ddns/tests/Makefile.am
src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
src/lib/dhcpsrv/d2_client_mgr.cc
src/lib/dhcpsrv/d2_client_mgr.h
src/lib/util/Makefile.am
src/lib/util/tests/Makefile.am
src/lib/util/tests/watch_socket_unittests.cc [moved from src/lib/dhcp_ddns/tests/watch_socket_unittests.cc with 90% similarity]
src/lib/util/watch_socket.cc [moved from src/lib/dhcp_ddns/watch_socket.cc with 92% similarity]
src/lib/util/watch_socket.h [moved from src/lib/dhcp_ddns/watch_socket.h with 97% similarity]

index 0dadcb93d6be8fd32701dc8ec2bbd7472ccd82c3..5d79777971f7306080bc026ed2e3d4d51781d542 100644 (file)
@@ -34,7 +34,6 @@ libkea_dhcp_ddns_la_SOURCES += dhcp_ddns_log.cc dhcp_ddns_log.h
 libkea_dhcp_ddns_la_SOURCES += ncr_io.cc ncr_io.h
 libkea_dhcp_ddns_la_SOURCES += ncr_msg.cc ncr_msg.h
 libkea_dhcp_ddns_la_SOURCES += ncr_udp.cc ncr_udp.h
-libkea_dhcp_ddns_la_SOURCES += watch_socket.cc watch_socket.h
 
 nodist_libkea_dhcp_ddns_la_SOURCES = dhcp_ddns_messages.cc dhcp_ddns_messages.h
 
index c22a57f61e1565fa21f425c4028fa6d4c563dce0..683147f04bc4fc7c882011f13bb66d5acccc8700 100644 (file)
@@ -260,7 +260,7 @@ NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
 
     send_callback_->setDataSource(server_endpoint_);
 
-    watch_socket_.reset(new WatchSocket());
+    watch_socket_.reset(new util::WatchSocket());
 }
 
 void
index 1af030830027e52500457972d05fe3742ee666ee..89646d118c575337b30d1722a51cf70d68f8c2e7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
 #include <asiolink/udp_endpoint.h>
 #include <asiolink/udp_socket.h>
 #include <dhcp_ddns/ncr_io.h>
-#include <dhcp_ddns/watch_socket.h>
 #include <util/buffer.h>
+#include <util/watch_socket.h>
 
 #include <boost/shared_array.hpp>
 
@@ -579,7 +579,7 @@ private:
     bool reuse_address_;
 
     /// @brief Pointer to WatchSocket instance supplying the "select-fd".
-    WatchSocketPtr watch_socket_;
+    util::WatchSocketPtr watch_socket_;
 };
 
 } // namespace isc::dhcp_ddns
index 3e6f0bd43e9e1d629b6606c62cb58515138d5265..d870e3825228703adb07ac0f73518e6ac89b9ea7 100644 (file)
@@ -30,7 +30,6 @@ libdhcp_ddns_unittests_SOURCES  = run_unittests.cc
 libdhcp_ddns_unittests_SOURCES += ncr_unittests.cc
 libdhcp_ddns_unittests_SOURCES += ncr_udp_unittests.cc
 libdhcp_ddns_unittests_SOURCES += test_utils.cc test_utils.h
-libdhcp_ddns_unittests_SOURCES += watch_socket_unittests.cc
 
 libdhcp_ddns_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
 
index b1a463d962c0482e94f54cf37ea2fef54d078de5..b065abf739bd46aa8faf8ebc64d3326d42e1213f 100644 (file)
@@ -362,7 +362,7 @@ TEST(NameChangeUDPSenderBasicTest, basicSendTests) {
     int select_fd = sender.getSelectFd();
 
     // Verify select_fd is valid and currently shows no ready to read.
-    ASSERT_NE(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID, select_fd);
+    ASSERT_NE(util::WatchSocket::SOCKET_NOT_VALID, select_fd);
 
     // Make sure select_fd does evaluates to not ready via select and
     // that ioReady() method agrees.
@@ -747,7 +747,7 @@ TEST(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequest) {
     close(sender.getSelectFd());
 
     // Send should fail as we interferred by closing the select-fd.
-    ASSERT_THROW(sender.sendRequest(ncr), WatchSocketError);
+    ASSERT_THROW(sender.sendRequest(ncr), util::WatchSocketError);
 
     // Verify we didn't invoke the handler.
     EXPECT_EQ(0, ncr_handler.pass_count_);
@@ -827,7 +827,7 @@ TEST(NameChangeUDPSenderBasicTest, watchSocketBadRead) {
     // Interfere by reading part of the marker from the select-fd.
     uint32_t buf = 0;
     ASSERT_EQ((read (select_fd, &buf, 1)), 1);
-    ASSERT_NE(WatchSocket::MARKER, buf);
+    ASSERT_NE(util::WatchSocket::MARKER, buf);
 
     // Run one handler. This should execute the send completion handler
     // after sending the message.  Duing completion handling clearing the
index bad5073123e943bcf871feb4213bbdd4cc520283..70b00ae49d0ed1ec8f2c11696d3c01d546e6f3c4 100644 (file)
@@ -30,7 +30,7 @@ namespace dhcp {
 
 D2ClientMgr::D2ClientMgr() : d2_client_config_(new D2ClientConfig()),
     name_change_sender_(), private_io_service_(),
-    registered_select_fd_(dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
+    registered_select_fd_(util::WatchSocket::SOCKET_NOT_VALID) {
     // Default constructor initializes with a disabled configuration.
 }
 
@@ -275,9 +275,9 @@ D2ClientMgr::amSending() const {
 void
 D2ClientMgr::stopSender() {
     /// Unregister sender's select-fd.
-    if (registered_select_fd_ != dhcp_ddns::WatchSocket::SOCKET_NOT_VALID) {
+    if (registered_select_fd_ != util::WatchSocket::SOCKET_NOT_VALID) {
         IfaceMgr::instance().deleteExternalSocket(registered_select_fd_);
-        registered_select_fd_ = dhcp_ddns::WatchSocket::SOCKET_NOT_VALID;
+        registered_select_fd_ = util::WatchSocket::SOCKET_NOT_VALID;
     }
 
     // If its not null, call stop.
index eccccbee4d34b4a630dc3fc2770b21d270d81094..076cc0de8494dcd776808d8e3124f476360ed232 100644 (file)
@@ -409,7 +409,7 @@ protected:
     /// @brief Fetches the select-fd that is currently registered.
     ///
     /// @return The currently registered select-fd or
-    /// dhcp_ddns::WatchSocket::SOCKET_NOT_VALID.
+    /// util::WatchSocket::SOCKET_NOT_VALID.
     ///
     /// @note This is only exposed for testing purposes.
     int getRegisteredSelectFd();
index ea120b0720757ace00463fe7b102a924b363ac2d..52bab0825001f9b546f8c3e7090e064768a54028 100644 (file)
@@ -26,6 +26,7 @@ libkea_util_la_SOURCES += range_utilities.h
 libkea_util_la_SOURCES += signal_set.cc signal_set.h
 libkea_util_la_SOURCES += stopwatch.cc stopwatch.h
 libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h
+libkea_util_la_SOURCES += watch_socket.cc watch_socket.h
 libkea_util_la_SOURCES += encode/base16_from_binary.h
 libkea_util_la_SOURCES += encode/base32hex.h encode/base64.h
 libkea_util_la_SOURCES += encode/base32hex_from_binary.h
index a7ded73d353b76c8a7877a14fe3fb7a0fefc983e..f5119cf41a41c5b4de8fd986095a6bad5e9ec803 100644 (file)
@@ -51,6 +51,8 @@ run_unittests_SOURCES += time_utilities_unittest.cc
 run_unittests_SOURCES += range_utilities_unittest.cc
 run_unittests_SOURCES += signal_set_unittest.cc
 run_unittests_SOURCES += stopwatch_unittest.cc
+run_unittests_SOURCES += watch_socket_unittests.cc
+
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
similarity index 90%
rename from src/lib/dhcp_ddns/tests/watch_socket_unittests.cc
rename to src/lib/util/tests/watch_socket_unittests.cc
index cb10323336dc2b4f31ee4c558168cbb114471aae..465084c94ebbb7400464bce204caa353019bdc57 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -12,8 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 #include <config.h>
-#include <dhcp_ddns/watch_socket.h>
-#include <test_utils.h>
+#include <util/watch_socket.h>
 
 #include <gtest/gtest.h>
 
 
 using namespace std;
 using namespace isc;
-using namespace isc::dhcp_ddns;
+using namespace isc::util;
 
 namespace {
 
+/// @brief Returns the result of select() given an fd to check for read status.
+///
+/// @param fd_to_check The file descriptor to test
+///
+/// @return Returns less than one on an error, 0 if the fd is not ready to
+/// read, > 0 if it is ready to read. 
+int selectCheck(int fd_to_check) {
+    fd_set read_fds;
+    int maxfd = 0;
+
+    FD_ZERO(&read_fds);
+
+    // Add this socket to listening set
+    FD_SET(fd_to_check,  &read_fds);
+    maxfd = fd_to_check;
+
+    struct timeval select_timeout;
+    select_timeout.tv_sec = 0;
+    select_timeout.tv_usec = 0;
+
+    return (select(maxfd + 1, &read_fds, NULL, NULL, &select_timeout));
+}
+
 /// @brief Tests the basic functionality of WatchSocket.
 TEST(WatchSocketTest, basics) {
     WatchSocketPtr watch;
similarity index 92%
rename from src/lib/dhcp_ddns/watch_socket.cc
rename to src/lib/util/watch_socket.cc
index 7139f8270c541d75d39a2ee7958ea30a9e47fdff..a364edcd0486dd1cdb4755eca515ed2ecbe7cdbe 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
 
 /// @file watch_socket.cc
 
-#include <dhcp_ddns/dhcp_ddns_log.h>
-#include <dhcp_ddns/watch_socket.h>
+//#include <dhcp_ddns/dhcp_ddns_log.h>
+#include <util/watch_socket.h>
 
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/select.h>
 
 namespace isc {
-namespace dhcp_ddns {
+namespace util {
 
 
 const int WatchSocket::SOCKET_NOT_VALID;
@@ -124,9 +124,9 @@ WatchSocket::closeSocket() {
     // destructors that throw.
     if (source_ != SOCKET_NOT_VALID) {
         if (close(source_)) {
-            const char* errstr = strerror(errno);
+/*            const char* errstr = strerror(errno);
             LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SOURCE_CLOSE_ERROR)
-                      .arg(errstr);
+                      .arg(errstr); */
         }
 
         source_ = SOCKET_NOT_VALID;
@@ -134,9 +134,9 @@ WatchSocket::closeSocket() {
 
     if (sink_ != SOCKET_NOT_VALID) {
         if (close(sink_)) {
-            const char* errstr = strerror(errno);
+/*            const char* errstr = strerror(errno);
             LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_WATCH_SINK_CLOSE_ERROR)
-                      .arg(errstr);
+                      .arg(errstr); */
         }
 
         sink_ = SOCKET_NOT_VALID;
@@ -148,5 +148,5 @@ WatchSocket::getSelectFd() {
     return (sink_);
 }
 
-} // namespace isc::dhcp_ddns
+} // namespace isc::util
 } // namespace isc
similarity index 97%
rename from src/lib/dhcp_ddns/watch_socket.h
rename to src/lib/util/watch_socket.h
index 85c3799864489c62873e6f076a3cdd5587ccddf2..0bdca4acf1be28651705bea846fe189b023e3fc5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -24,7 +24,7 @@
 #include <stdint.h>
 
 namespace isc {
-namespace dhcp_ddns {
+namespace util {
 
 /// @brief Exception thrown if an error occurs during IO source open.
 class WatchSocketError : public isc::Exception {
@@ -132,7 +132,7 @@ private:
 /// @brief Defines a smart pointer to an instance of a WatchSocket.
 typedef boost::shared_ptr<WatchSocket> WatchSocketPtr;
 
-} // namespace isc::dhcp_ddns
+} // namespace isc::util
 } // namespace isc
 
 #endif