From: Francis Dupont Date: Thu, 11 Dec 2025 08:25:47 +0000 (+0100) Subject: [#4258] Avoid copies X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=570294c3d3cb8177fe894a75e6a8fbc58b87922d;p=thirdparty%2Fkea.git [#4258] Avoid copies --- diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index 43d64d6a4e..18e923b2fe 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -922,15 +922,16 @@ IfaceMgr::clearBoundAddresses() { } void -IfaceMgr::handleClosedExternalSocket(SocketCallbackInfo s) { +IfaceMgr::handleClosedExternalSocket(SocketCallbackInfo const& s) { errno = 0; if (fcntl(s.socket_, F_GETFD) < 0 && (errno == EBADF)) { - s.unusable_ = true; + SocketCallbackInfo x(s); + x.unusable_ = true; auto& idx = callbacks_.get<1>(); auto it = idx.find(s.socket_); // Expect that the external socket is still there! if (it != idx.end()) { - idx.replace(it, s); + idx.replace(it, x); } isc_throw(SocketFDError, "unexpected state (closed) for fd: " << s.socket_); } @@ -1205,7 +1206,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec / { std::lock_guard lock(callbacks_mutex_); if (!callbacks_.empty()) { - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1272,7 +1273,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec / bool found = false; { std::lock_guard lock(callbacks_mutex_); - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1340,7 +1341,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /* { std::lock_guard lock(callbacks_mutex_); if (!callbacks_.empty()) { - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1381,7 +1382,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /* bool found = false; { std::lock_guard lock(callbacks_mutex_); - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1490,7 +1491,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ ) { std::lock_guard lock(callbacks_mutex_); if (!callbacks_.empty()) { - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1531,7 +1532,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ ) bool found = false; { std::lock_guard lock(callbacks_mutex_); - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1614,7 +1615,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ { std::lock_guard lock(callbacks_mutex_); if (!callbacks_.empty()) { - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } @@ -1681,7 +1682,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ bool found = false; { std::lock_guard lock(callbacks_mutex_); - for (SocketCallbackInfo s : callbacks_) { + for (SocketCallbackInfo const& s : callbacks_) { if (s.unusable_) { continue; } diff --git a/src/lib/dhcp/iface_mgr.h b/src/lib/dhcp/iface_mgr.h index 2d3d3c273d..2542f5c82f 100644 --- a/src/lib/dhcp/iface_mgr.h +++ b/src/lib/dhcp/iface_mgr.h @@ -1679,7 +1679,7 @@ private: /// @brief Handle closed external socket. /// /// @param s The external socket info. - void handleClosedExternalSocket(SocketCallbackInfo s); + void handleClosedExternalSocket(SocketCallbackInfo const& s); /// @brief Handle closed external sockets. void handleClosedExternalSockets();