From 890b0b86c4fcae3e3069c1676a7abb3e26a9b0cc Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:22:28 +0100 Subject: [PATCH] CUDPReceiver socket protected by mutex --- ecal/core/src/io/udp/udp_receiver.cpp | 9 +++++++++ ecal/core/src/io/udp/udp_receiver.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/ecal/core/src/io/udp/udp_receiver.cpp b/ecal/core/src/io/udp/udp_receiver.cpp index 0ddf70ab4f..922fb9a2d5 100644 --- a/ecal/core/src/io/udp/udp_receiver.cpp +++ b/ecal/core/src/io/udp/udp_receiver.cpp @@ -73,25 +73,34 @@ namespace eCAL bool CUDPReceiver::Destroy() { if (!m_socket_impl) return(false); + + const std::lock_guard lock(m_socket_mtx); m_socket_impl.reset(); + return(true); } bool CUDPReceiver::AddMultiCastGroup(const char* ipaddr_) { if (!m_socket_impl) return(false); + + const std::lock_guard lock(m_socket_mtx); return(m_socket_impl->AddMultiCastGroup(ipaddr_)); } bool CUDPReceiver::RemMultiCastGroup(const char* ipaddr_) { if (!m_socket_impl) return(false); + + const std::lock_guard lock(m_socket_mtx); return(m_socket_impl->RemMultiCastGroup(ipaddr_)); } size_t CUDPReceiver::Receive(char* buf_, size_t len_, int timeout_, ::sockaddr_in* address_ /* = nullptr */) { if (!m_socket_impl) return(0); + + const std::lock_guard lock(m_socket_mtx); return(m_socket_impl->Receive(buf_, len_, timeout_, address_)); } } diff --git a/ecal/core/src/io/udp/udp_receiver.h b/ecal/core/src/io/udp/udp_receiver.h index 500aaeec6c..d425f8c2f6 100644 --- a/ecal/core/src/io/udp/udp_receiver.h +++ b/ecal/core/src/io/udp/udp_receiver.h @@ -24,6 +24,7 @@ #pragma once #include +#include #include "ecal_receiver.h" namespace eCAL @@ -45,6 +46,7 @@ namespace eCAL protected: bool m_use_npcap; + std::mutex m_socket_mtx; std::shared_ptr m_socket_impl; }; }