Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure correct udp socket concurrent handling by mutex #1289

Merged
merged 1 commit into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions ecal/core/src/io/udp_receiver.cpp
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_));
}
}
4 changes: 3 additions & 1 deletion ecal/core/src/io/udp_receiver.h
Expand Up @@ -24,6 +24,7 @@
#pragma once

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

namespace eCAL
Expand All @@ -44,7 +45,8 @@ namespace eCAL
size_t Receive(char* buf_, size_t len_, int timeout_, ::sockaddr_in* address_ = nullptr) override;

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