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

udp receive logic redesign #1271

Merged
merged 25 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b3d89f8
receive thread now inside CSampleReceiver
rex-schilasky Nov 24, 2023
e8011af
one common cycle time for all udp receiver
rex-schilasky Nov 24, 2023
7892840
logging receiver moved to io/udp
rex-schilasky Nov 25, 2023
e6c2458
eCAL::CThread replaced finally by std::thread
rex-schilasky Nov 26, 2023
f0baa8a
missing include fixed
rex-schilasky Nov 26, 2023
7486257
missing header fixed
rex-schilasky Nov 26, 2023
a238c1c
exclude rec_rpc_tests to run all other tests for now
rex-schilasky Nov 27, 2023
aa39d7c
ecal_thread back again :-) (now based on std::thread)
rex-schilasky Nov 28, 2023
8de0a9a
udp ttl 1 for all platforms in local mode
rex-schilasky Nov 29, 2023
181506f
dynamic sleep time for rec rpc test
rex-schilasky Nov 29, 2023
e0a969e
timoout for GetTopics test adapted
rex-schilasky Nov 29, 2023
f0061ca
CallbackThread renamed to CCallbackThread (all classes shall start wi…
rex-schilasky Nov 30, 2023
71c79a8
comment fixed
rex-schilasky Dec 1, 2023
61455d5
new subfolder for udp message (de)fragmentation io/udp/fragmentation
rex-schilasky Dec 5, 2023
82c4237
some more cleanups in the udp functions file structure
rex-schilasky Dec 5, 2023
94eca56
separate send module for log messages
rex-schilasky Dec 5, 2023
f406a3f
cleanup file structure
rex-schilasky Dec 6, 2023
59dc218
linux fix
rex-schilasky Dec 6, 2023
56a518e
clang-tidy
rex-schilasky Dec 6, 2023
1771300
removed some udp io dependencies from eCAL::Process and eCAL::Config
rex-schilasky Dec 7, 2023
69da2b1
includes cleaned up
rex-schilasky Dec 7, 2023
4a90d87
minor alignments with ecal-core-udp
rex-schilasky Dec 12, 2023
ac01c7f
ecal_win_network.h removed
rex-schilasky Dec 13, 2023
36d8dc7
bugfix in udp receiver destruction
rex-schilasky Dec 14, 2023
9073656
protecting udp receive sockets by mutex (should fix #1212)
rex-schilasky Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ if(BUILD_ECAL_TESTS)
# ------------------------------------------------------
# test ecal
# ------------------------------------------------------
add_subdirectory(testing/ecal/clientserver_test) #THIS TEST IS NOT ABLE TO RUN ON GH ACTIONS
add_subdirectory(testing/ecal/clientserver_test)

add_subdirectory(testing/ecal/core_test)
add_subdirectory(testing/ecal/event_test)
Expand Down
12 changes: 11 additions & 1 deletion app/rec/rec_tests/rec_rpc_tests/src/external_ecal_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ ExternalEcalRecInstance::ExternalEcalRecInstance(bool gui)
return;
}

std::this_thread::sleep_for(std::chrono::milliseconds(3000));
for (int i = 0; i < 20; ++i)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));

eCAL::pb::rec_server::RecServerConfig config_pb;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'config_pb' is not initialized [cppcoreguidelines-init-variables]

Suggested change
eCAL::pb::rec_server::RecServerConfig config_pb;
eCAL::pb::rec_server::RecServerConfig config_pb = 0;

auto error = GetConfigViaRpc(config_pb);
if (!error)
{
break;
}
}

if (gui)
{
Expand Down
96 changes: 60 additions & 36 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,43 +137,63 @@ endif()
######################################
# io/udp
######################################
# io/udp/fragmentation
set(ecal_io_udp_fragmentation_src
src/io/udp/fragmentation/msg_type.h
src/io/udp/fragmentation/rcv_fragments.cpp
src/io/udp/fragmentation/rcv_fragments.h
src/io/udp/fragmentation/snd_fragments.cpp
src/io/udp/fragmentation/snd_fragments.h
)

# io/udp/sendreceive (npcap)
if(ECAL_NPCAP_SUPPORT)
set(ecal_io_udp_src_npcap
src/io/udp/udp_receiver_npcap.cpp
src/io/udp/udp_receiver_npcap.h
set(ecal_io_udp_sendreceive_src_npcap
src/io/udp/sendreceive/udp_receiver_npcap.cpp
src/io/udp/sendreceive/udp_receiver_npcap.h
)
endif()

set(ecal_io_udp_src
src/io/udp/rcv_sample.cpp
src/io/udp/snd_raw_buffer.cpp
src/io/udp/snd_sample.cpp
src/io/udp/udp_configurations.cpp
src/io/udp/udp_init.cpp
src/io/udp/udp_receiver.cpp
src/io/udp/udp_receiver_asio.cpp
src/io/udp/udp_sender.cpp
src/io/udp/ecal_receiver.h
src/io/udp/msg_type.h
src/io/udp/rcv_sample.h
src/io/udp/snd_raw_buffer.h
src/io/udp/snd_sample.h
src/io/udp/udp_configurations.h
src/io/udp/udp_init.h
src/io/udp/udp_receiver.h
src/io/udp/udp_receiver_base.h
src/io/udp/udp_receiver_asio.h
src/io/udp/udp_sender.h
${ecal_io_udp_src_npcap}
)

# io/udp/linux
# io/udp/sendreceive
set(ecal_io_udp_sendreceive_src
src/io/udp/sendreceive/udp_receiver.cpp
src/io/udp/sendreceive/udp_receiver.h
src/io/udp/sendreceive/udp_receiver_asio.cpp
src/io/udp/sendreceive/udp_receiver_asio.h
src/io/udp/sendreceive/udp_sender.cpp
src/io/udp/sendreceive/udp_sender.h
${ecal_io_udp_sendreceive_src_npcap}
)

# io/udp/sendreceive/linux
if(UNIX)
set(ecal_io_udp_linux_src
src/io/udp/linux/ecal_socket_option_linux.h
set(ecal_io_udp_sendreceive_linux_src
src/io/udp/sendreceive/linux/socket_os.h
)
endif()

# io/udp/sendreceive/win32
if (WIN32)
set(ecal_io_udp_sendreceive_win_src
src/io/udp/sendreceive/win32/socket_os.h
)
endif()

# io/udp
set(ecal_io_udp_src
src/io/udp/ecal_udp_configurations.cpp
src/io/udp/ecal_udp_configurations.h
src/io/udp/ecal_udp_logging_receiver.cpp
src/io/udp/ecal_udp_logging_receiver.h
src/io/udp/ecal_udp_logging_sender.cpp
src/io/udp/ecal_udp_logging_sender.h
src/io/udp/ecal_udp_sample_receiver.cpp
src/io/udp/ecal_udp_sample_receiver.h
src/io/udp/ecal_udp_sample_sender.cpp
src/io/udp/ecal_udp_sample_sender.h
src/io/udp/ecal_udp_topic2mcast.h
)

######################################
# logging
######################################
Expand All @@ -189,10 +209,8 @@ set(ecal_logging_src
set(ecal_monitoring_src
src/monitoring/ecal_monitoring_def.cpp
src/monitoring/ecal_monitoring_impl.cpp
src/monitoring/ecal_monitoring_threads.cpp
src/monitoring/ecal_monitoring_def.h
src/monitoring/ecal_monitoring_impl.h
src/monitoring/ecal_monitoring_threads.h
)

######################################
Expand Down Expand Up @@ -297,7 +315,6 @@ set(ecal_util_src
src/util/convert_utf.cpp
src/util/convert_utf.h
src/util/ecal_expmap.h
src/util/ecal_thread.cpp
src/util/ecal_thread.h
src/util/getenvvar.h
src/util/sys_usage.cpp
Expand All @@ -323,13 +340,13 @@ set(ecal_cmn_src
src/ecal_global_accessors.h
src/ecal_globals.h
src/ecal_sample_to_topicinfo.h
src/topic2mcast.h
)
if (WIN32)
list (APPEND
ecal_cmn_src
src/ecal_win_main.h
src/ecal_win_socket.h
src/ecal_win_network.cpp
src/ecal_win_network.h
)
endif()

Expand Down Expand Up @@ -447,9 +464,12 @@ ecal_add_ecal_shared_library(${PROJECT_NAME}
${ecal_io_mtx_win_src}
${ecal_io_shm_src}
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_sendreceive_src}
${ecal_io_udp_src}
${ecal_io_udp_linux_src}
${ecal_io_udp_sendreceive_linux_src}
${ecal_io_udp_sendreceive_win_src}
${ecal_logging_src}
${ecal_monitoring_src}
${ecal_pubsub_src}
Expand Down Expand Up @@ -567,7 +587,11 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.8.0")
${ecal_io_shm_src}
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_sendreceive_src}
${ecal_io_udp_src}
${ecal_io_udp_sendreceive_linux_src}
${ecal_io_udp_sendreceive_win_src}
${ecal_logging_src}
${ecal_monitoring_src}
${ecal_pubsub_src}
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/ecal_monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace eCAL
*
* @return Zero if succeeded.
**/
ECAL_DEPRECATE_SINCE_5_12("use GetMonitoring and publish yourself")
ECAL_DEPRECATE_SINCE_5_12("Function is no longer implemented. Instead use GetMonitoring")
ECAL_API int PubMonitoring(bool state_, std::string name_ = "ecal.monitoring");

/**
Expand All @@ -118,7 +118,7 @@ namespace eCAL
*
* @return Zero if succeeded.
**/
ECAL_DEPRECATE_SINCE_5_12("use GetLogging and publish yourself")
ECAL_DEPRECATE_SINCE_5_12("Function is no longer implemented. Instead use GetLogging")
ECAL_API int PubLogging(bool state_, std::string name_ = "ecal.logging");
}
/** @example monitoring_rec.cpp
Expand Down
10 changes: 2 additions & 8 deletions ecal/core/src/ecal_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,8 @@
/* delta time to check timeout for data readers in ms */
#define CMN_DATAREADER_TIMEOUT_RESOLUTION_MS 100

/* cylce time udp registration receive thread in ms */
#define CMN_REGISTRATION_RECEIVE_THREAD_CYCLE_TIME_MS 1000

/* cylce time udp logging receive thread in ms */
#define CMN_LOGGING_RECEIVE_THREAD_CYCLE_TIME_MS 1000

/* cylce time udp paylaod receive thread in ms */
#define CMN_PAYLOAD_RECEIVE_THREAD_CYCLE_TIME_MS 1000
/* cylce time udp receive threads in ms */
#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: macro 'CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS' defines an integral constant; prefer an enum instead [modernize-macro-to-enum]

#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS           1000
        ^


Comment on lines +178 to 179
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: replace macro with enum [modernize-macro-to-enum]

Suggested change
#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000
enum {
CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000};

/**********************************************************************************************/
/* events */
Expand Down
11 changes: 8 additions & 3 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
**/

#include "ecal_globals.h"
#include "io/udp/udp_init.h"
#include "ecal_win_network.h"

#include "config/ecal_config_reader.h"

#include <stdexcept>
Expand All @@ -44,8 +45,10 @@ namespace eCAL
// will be set if any new module was initialized
bool new_initialization(false);

// this is needed here for functions like "GetHostName" on windows
#ifdef ECAL_OS_WINDOWS
// windows network startup
Net::Initialize();
#endif /* ECAL_OS_WINDOWS */

/////////////////////
// CONFIG
Expand Down Expand Up @@ -297,8 +300,10 @@ namespace eCAL
log_instance = nullptr;
config_instance = nullptr;

// last not least we close all
#ifdef ECAL_OS_WINDOWS
// windows network cleanup
Net::Finalize();
#endif /* ECAL_OS_WINDOWS */

initialized = false;

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/ecal_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "registration/ecal_registration_receiver.h"
#include "ecal_globals.h"
#include "ecal_process.h"
#include "io/udp/udp_configurations.h"
#include "io/udp/ecal_udp_configurations.h"

#include <array>
#include <chrono>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@
*/

/**
* @brief UDP initialization
* @brief Win32 network initialization
**/

#include <ecal/ecal_os.h>

#include <cstdio>
#include <atomic>

#ifdef ECAL_OS_WINDOWS
#include "ecal_win_socket.h"
#endif /* ECAL_OS_WINDOWS */
#if defined(_MSC_VER) && defined(__clang__) && !defined(CINTERFACE)
#define CINTERFACE
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <winsock2.h> //NOLINT
#include <Ws2tcpip.h> //NOLINT

#undef CINTERFACE

static std::atomic<int> g_socket_init_refcnt(0);

Expand All @@ -41,7 +48,6 @@ namespace eCAL
g_socket_init_refcnt++;
if(g_socket_init_refcnt == 1)
{
#ifdef ECAL_OS_WINDOWS
const WORD wVersionRequested = MAKEWORD(2, 2);

WSADATA wsaData;
Expand All @@ -67,7 +73,6 @@ namespace eCAL
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup();
}
#endif /* ECAL_OS_WINDOWS */
}
return(0);
}
Expand All @@ -79,11 +84,8 @@ namespace eCAL
g_socket_init_refcnt--;
if(g_socket_init_refcnt == 0)
{
#ifdef ECAL_OS_WINDOWS
WSACleanup();
#endif /* ECAL_OS_WINDOWS */
}

return(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/**
* @brief UDP initialization
* @brief Win32 network initialization
**/

#pragma once
Expand Down
Loading
Loading