]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4141] addressed review comments
authorRazvan Becheriu <razvan@isc.org>
Sat, 1 Nov 2025 06:50:18 +0000 (08:50 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 3 Nov 2025 18:59:34 +0000 (18:59 +0000)
src/lib/dhcp/iface_mgr.cc
src/lib/testutils/unix_control_client.h
src/lib/util/fd_event_handler.h
src/lib/util/ready_check.h
src/lib/util/select_event_handler.cc
src/lib/util/select_event_handler.h

index 520a846cf8f64b7d1269bbf77a7a580f5136a729..5cd5fdfcc4d490a1509e7d45e7a98fb7aa43916e 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
+#include <sys/ioctl.h>
 #include <string.h>
 
 using namespace std;
@@ -1258,8 +1259,8 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
     /// @todo: marginal performance optimization. We could create the set once
     /// and then use its copy for select(). Please note that select() modifies
     /// provided set to indicated which sockets have something to read.
-    /// @note: this can be achieved with FDEventHandler (initialize only if max_fd_ is 0)
-    /// and do not clear the state.
+    /// @note: this can be achieved with FDEventHandler (initialize only if
+    /// max_fd_ is 0) and do not clear the state.
     for (const IfacePtr& iface : ifaces_) {
         for (const SocketInfo& s : iface->getSockets()) {
             // Only deal with IPv4 addresses.
@@ -1390,8 +1391,8 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
     /// @todo: marginal performance optimization. We could create the set once
     /// and then use its copy for select(). Please note that select() modifies
     /// provided set to indicated which sockets have something to read.
-    /// @note: this can be achieved with FDEventHandler (initialize only if max_fd_ is 0)
-    /// and do not clear the state.
+    /// @note: this can be achieved with FDEventHandler (initialize only if
+    /// max_fd_ is 0) and do not clear the state.
     for (const IfacePtr& iface : ifaces_) {
         for (const SocketInfo& s : iface->getSockets()) {
             // Only deal with IPv6 addresses.
@@ -1638,7 +1639,7 @@ IfaceMgr::receiveDHCP4Packets() {
         errno = 0;
 
         // Select with null timeouts to wait indefinitely an event
-        int result = receiver_fd_event_handler_->waitEvent(0, 0);
+        int result = receiver_fd_event_handler_->waitEvent(0, 0, false);
 
         // Re-check the watch socket.
         if (dhcp_receiver_->shouldTerminate()) {
@@ -1705,7 +1706,7 @@ IfaceMgr::receiveDHCP6Packets() {
         errno = 0;
 
         // Select with null timeouts to wait indefinitely an event
-        int result = receiver_fd_event_handler_->waitEvent(0, 0);
+        int result = receiver_fd_event_handler_->waitEvent(0, 0, false);
 
         // Re-check the watch socket.
         if (dhcp_receiver_->shouldTerminate()) {
@@ -1844,8 +1845,10 @@ IfaceMgr::getSocket(const isc::dhcp::Pkt6Ptr& pkt) {
             // If we want to send something to link-local and the socket is
             // bound to link-local or we want to send to global and the socket
             // is bound to global, then use it as candidate
-            if ((pkt->getRemoteAddr().isV6LinkLocal() && s->addr_.isV6LinkLocal()) ||
-                (!pkt->getRemoteAddr().isV6LinkLocal() && !s->addr_.isV6LinkLocal())) {
+            if ((pkt->getRemoteAddr().isV6LinkLocal() &&
+                 s->addr_.isV6LinkLocal()) ||
+                (!pkt->getRemoteAddr().isV6LinkLocal() &&
+                 !s->addr_.isV6LinkLocal())) {
                 candidate = s;
             }
         }
index 19b487bb31db804aac71a61d8bff6ae9576748a1..d0a58a72641c1168bab265211a05cdc60e39fe69 100644 (file)
@@ -55,7 +55,8 @@ public:
     /// @param read_check flag to check socket for read ready state
     /// @param write_check flag to check socket for write ready state
     /// @return -1 on error, 0 if no data is available, 1 if data is ready
-    int selectCheck(const unsigned int timeout_sec, bool read_check, bool write_check);
+    int selectCheck(const unsigned int timeout_sec, bool read_check,
+                    bool write_check);
 
     /// @brief Retains the fd of the open socket
     int socket_fd_;
index e8e93986902c18b6a5fffa34595ac297faa9b3d2..73d2425dd22a2c7c8bf026c7458d74d59d6cf0cf 100644 (file)
@@ -44,10 +44,13 @@ public:
     /// @brief Wait for events on registered file descriptors.
     ///
     /// @param timeout_sec The wait timeout in seconds.
-    /// @param timeout_usec The wait timeout in micro seconds
+    /// @param timeout_usec The wait timeout in micro seconds.
+    /// @param use_timeout Flag which indicates if function should wait
+    /// with no timeout (wait forever).
     /// @return -1 on error, 0 if no data is available (timeout expired),
     /// 1 if data is ready.
-    virtual int waitEvent(uint32_t timeout_sec, uint32_t timeout_usec = 0) = 0;
+    virtual int waitEvent(uint32_t timeout_sec, uint32_t timeout_usec = 0,
+                          bool use_timeout = true) = 0;
 
     /// @brief Check if file descriptor is ready for read operation.
     ///
index 6cc734d5f6497aad30110b801f19b8563074d30b..f06765dc6d453e094051a3ac85a084a12d365e9b 100644 (file)
@@ -15,7 +15,8 @@ namespace util {
 /// @param read_check flag to check socket for read ready state
 /// @param write_check flag to check socket for write ready state
 /// @return -1 on error, 0 if no data is available, 1 if data is ready
-int selectCheck(const int fd_to_check, const unsigned int timeout_sec = 0, bool read_check = true, bool write_check = false);
+int selectCheck(const int fd_to_check, const unsigned int timeout_sec = 0,
+                bool read_check = true, bool write_check = false);
 
 } // end of isc::util namespace
 } // end of isc namespace
index e4daf7a9631b7e3497d54ad44a3c5c31764b0b4d..6334bc73c61c1fb2b427c5bcf988b7fba0c832fe 100644 (file)
@@ -9,6 +9,8 @@
 #include <exceptions/exceptions.h>
 #include <util/select_event_handler.h>
 
+#include <cstring>
+
 #ifndef FD_COPY
 #define FD_COPY(orig, copy) \
     do { \
@@ -43,20 +45,25 @@ void SelectEventHandler::add(int fd, bool read /* = true */, bool write /* = fal
     }
 }
 
-int SelectEventHandler::waitEvent(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
+int SelectEventHandler::waitEvent(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */,
+                                  bool use_timeout /* = true */) {
     // Sanity check for microsecond timeout.
     if (timeout_usec >= 1000000) {
         isc_throw(BadValue, "fractional timeout must be shorter than"
                   " one million microseconds");
     }
     struct timeval select_timeout;
-    select_timeout.tv_sec = timeout_sec;
-    select_timeout.tv_usec = timeout_usec;
+    struct timeval* select_timeout_p = 0;
+    if (use_timeout) {
+        select_timeout.tv_sec = timeout_sec;
+        select_timeout.tv_usec = timeout_usec;
+        select_timeout_p = &select_timeout;
+    }
 
     FD_COPY(&read_fd_set_, &read_fd_set_data_);
     FD_COPY(&write_fd_set_, &write_fd_set_data_);
 
-    return (select(max_fd_ + 1, &read_fd_set_data_, &write_fd_set_data_, 0, &select_timeout));
+    return (select(max_fd_ + 1, &read_fd_set_data_, &write_fd_set_data_, 0, select_timeout_p));
 }
 
 bool SelectEventHandler::readReady(int fd) {
index 579a7c00daaee45e8e38f5b2c3b6f5a9b0d63778..45f9e96f0f961a4ca066b0f1b4a75891eb22694d 100644 (file)
@@ -36,10 +36,13 @@ public:
     /// @brief Wait for events on registered file descriptors.
     ///
     /// @param timeout_sec The wait timeout in seconds.
-    /// @param timeout_usec The wait timeout in micro seconds
+    /// @param timeout_usec The wait timeout in micro seconds.
+    /// @param use_timeout Flag which indicates if function should wait
+    /// with no timeout (wait forever).
     /// @return -1 on error, 0 if no data is available (timeout expired),
     /// 1 if data is ready.
-    int waitEvent(uint32_t timeout_sec, uint32_t timeout_usec = 0);
+    int waitEvent(uint32_t timeout_sec, uint32_t timeout_usec = 0,
+                  bool use_timeout = true);
 
     /// @brief Check if file descriptor is ready for read operation.
     ///