Skip to content

Commit

Permalink
CUDPReceiver socket protected by mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Dec 14, 2023
1 parent 210d236 commit 890b0b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ecal/core/src/io/udp/udp_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,34 @@ namespace eCAL
bool CUDPReceiver::Destroy()
{
if (!m_socket_impl) return(false);

const std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(m_socket_mtx);
return(m_socket_impl->Receive(buf_, len_, timeout_, address_));
}
}
2 changes: 2 additions & 0 deletions ecal/core/src/io/udp/udp_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#pragma once

#include <memory>
#include <mutex>
#include "ecal_receiver.h"

namespace eCAL
Expand All @@ -45,6 +46,7 @@ namespace eCAL

protected:
bool m_use_npcap;
std::mutex m_socket_mtx;
std::shared_ptr<CUDPReceiverBase> m_socket_impl;
};
}

0 comments on commit 890b0b8

Please sign in to comment.