-
Notifications
You must be signed in to change notification settings - Fork 177
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
Conversation
CReceiveSlot logic in separate unit rcv_sample_slot.cpp shm monitoring registration simplified
buggy thread usage removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rex-schilasky I don't think I can review this just by looking at it, I guess it needs to be reviewed in a 1:1 session.
@@ -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("No more implemented") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is missleading. How about "The function PubMonitoring is no longer implemented. Instead use GetMonitoring
and publish yourself"?
new subfolder for higher level udp protobuf message handling io/udp/protobuf
cleanup naming add IO::UDP namespace for internal (IO) UDP logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There were too many comments to post at once. Showing the first 20 out of 34. Check the log or trigger a new build to see more.
{ | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
|
||
eCAL::pb::rec_server::RecServerConfig config_pb; |
There was a problem hiding this comment.
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]
eCAL::pb::rec_server::RecServerConfig config_pb; | |
eCAL::pb::rec_server::RecServerConfig config_pb = 0; |
#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000 | ||
|
There was a problem hiding this comment.
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]
#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000 | |
enum { | |
CMN_UDP_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 |
There was a problem hiding this comment.
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
^
{ | ||
namespace UDP | ||
{ | ||
class CLoggingReceiver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: class 'CLoggingReceiver' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
class CLoggingReceiver
^
if (m_sample_receiver == nullptr) return(0); | ||
|
||
// read sample_name size | ||
const unsigned short sample_name_size = ((unsigned short*)(msg_buffer_.data()))[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
const unsigned short sample_name_size = ((unsigned short*)(msg_buffer_.data()))[0];
^
size_t sent_sum(0); | ||
|
||
int32_t total_packet_num = int32_t(buf_len_ / MSG_PAYLOAD_SIZE); | ||
if (buf_len_ % MSG_PAYLOAD_SIZE) total_packet_num++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'unsigned long' -> bool [readability-implicit-bool-conversion]
if (buf_len_ % MSG_PAYLOAD_SIZE) total_packet_num++; | |
if ((buf_len_ % MSG_PAYLOAD_SIZE) != 0u) total_packet_num++; |
getifaddrs(&ifap); | ||
|
||
// create a list of network interfaces indexes | ||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'ifaddrs *' -> bool [readability-implicit-bool-conversion]
for (ifa = ifap; ifa; ifa = ifa->ifa_next) | |
for (ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) |
// create a list of network interfaces indexes | ||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) | ||
{ | ||
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'struct sockaddr *' -> bool [readability-implicit-bool-conversion]
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) | |
if ((ifa->ifa_addr != nullptr) && ifa->ifa_addr->sa_family == AF_PACKET) |
{ | ||
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) | ||
{ | ||
int index = if_nametoindex(ifa->ifa_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'index' of type 'int' can be declared 'const' [misc-const-correctness]
int index = if_nametoindex(ifa->ifa_name); | |
int const index = if_nametoindex(ifa->ifa_name); |
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) | ||
{ | ||
int index = if_nametoindex(ifa->ifa_name); | ||
if (index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
if (index) | |
if (index != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
} | ||
|
||
CSampleReceiver::CSampleReceiver(const IO::UDP::SReceiverAttr& attr_, HasSampleCallbackT has_sample_callback_, ApplySampleCallbackT apply_sample_callback_) : | ||
m_has_sample_callback(has_sample_callback_), m_apply_sample_callback(apply_sample_callback_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'has_sample_callback_' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]
ecal/core/src/io/udp/ecal_udp_sample_receiver.cpp:27:
+
+ #include <utility>
m_has_sample_callback(has_sample_callback_), m_apply_sample_callback(apply_sample_callback_) | |
m_has_sample_callback(std::move(has_sample_callback_)), m_apply_sample_callback(apply_sample_callback_) |
inline static bool set_socket_mcast_group_option(int socket, const char* ipaddr_, int option) | ||
{ | ||
// set the multicast socket option on all interfaces | ||
for (int iface : get_interface_index_list()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'iface' of type 'int' can be declared 'const' [misc-const-correctness]
for (int iface : get_interface_index_list()) | |
for (int const iface : get_interface_index_list()) |
group->sin_addr.s_addr = inet_addr(ipaddr_); | ||
group->sin_port = 0; | ||
|
||
int rc = setsockopt(socket, IPPROTO_IP, option, &group_req, sizeof(group_source_req)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'rc' of type 'int' can be declared 'const' [misc-const-correctness]
int rc = setsockopt(socket, IPPROTO_IP, option, &group_req, sizeof(group_source_req)); | |
int const rc = setsockopt(socket, IPPROTO_IP, option, &group_req, sizeof(group_source_req)); |
AddMultiCastGroup(attr_.address.c_str()); | ||
|
||
// state successful creation | ||
m_created = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'm_created' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
ecal/core/src/io/udp/sendreceive/udp_receiver_asio.cpp:39:
- m_created(false),
+ m_created(true),
m_created = true; | |
|
||
log_ = logging.SerializeAsString(); | ||
return((int)log_.size()); | ||
} | ||
|
||
int PubMonitoring(bool state_, std::string name_ /* = "ecal.monitoring"*/) | ||
int PubMonitoring(bool /*state_*/, std::string /*name_*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: the parameter #2 is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
int PubMonitoring(bool /*state_*/, std::string /*name_*/) | |
int PubMonitoring(bool /*state_*/, const std::string& /*name_*/) |
ecal/core/include/ecal/ecal_monitoring.h:110:
- ECAL_API int PubMonitoring(bool state_, std::string name_ = "ecal.monitoring");
+ ECAL_API int PubMonitoring(bool state_, const std::string& name_ = "ecal.monitoring");
bool m_reg_topics; | ||
bool m_reg_services; | ||
bool m_reg_process; | ||
static std::atomic<bool> m_created; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'm_created' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
static std::atomic<bool> m_created;
^
return_value &= ApplySample(sample); | ||
for (const auto& sample : sample_list.samples()) | ||
{ | ||
if (g_registration_receiver()) g_registration_receiver()->ApplySample(sample); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'CRegistrationReceiver *' -> bool [readability-implicit-bool-conversion]
if (g_registration_receiver()) g_registration_receiver()->ApplySample(sample); | |
if (g_registration_receiver() != nullptr) g_registration_receiver()->ApplySample(sample); |
@@ -84,6 +80,7 @@ namespace eCAL | |||
void EnableLoopback(bool state_); | |||
bool LoopBackEnabled() const { return m_loopback; }; | |||
|
|||
bool HasSample(const std::string& /*sample_name_*/) { return(true); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: method 'HasSample' can be made static [readability-convert-member-functions-to-static]
bool HasSample(const std::string& /*sample_name_*/) { return(true); }; | |
static bool HasSample(const std::string& /*sample_name_*/) { return(true); }; |
static std::atomic<bool> m_created; | ||
bool m_network; | ||
bool m_loopback; | ||
static std::atomic<bool> m_created; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'm_created' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
static std::atomic<bool> m_created;
^
* @param callback A callback function to be executed in the CallbackThread thread. | ||
*/ | ||
CCallbackThread(std::function<void()> callback) | ||
: callback_(callback) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: parameter 'callback' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]
ecal/core/src/util/ecal_thread.h:28:
+ #include <utility>
: callback_(callback) {} | |
: callback_(std::move(callback)) {} |
JoinMultiCastGroupTwice feature finally removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
m_created = true; | ||
} | ||
|
||
CUDPReceiverAsio::~CUDPReceiverAsio() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: an exception may be thrown in function '~CUDPReceiverAsio' which should not throw exceptions [bugprone-exception-escape]
CUDPReceiverAsio::~CUDPReceiverAsio()
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that you know what you are doing 😄
Description
UDP logic redesigned:
Related issues
Preparation for solving #1236
Fixes #1276
Cherry-pick to