-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat(nebula_hw_interfaces): better UDP socket #231
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
…o everywhere Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
…down Signed-off-by: Max SCHMELLER <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #231 +/- ##
==========================================
+ Coverage 26.10% 27.07% +0.97%
==========================================
Files 100 104 +4
Lines 9218 9455 +237
Branches 2215 2319 +104
==========================================
+ Hits 2406 2560 +154
- Misses 6423 6458 +35
- Partials 389 437 +48
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
… feat/better-udp-socket
…received Signed-off-by: Max SCHMELLER <[email protected]>
Unit tests have been written, but things like querying |
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 left some comments! Many are questions and there are no must-do changes but please have a look and I will approve once confirmed.
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Outdated
Show resolved
Hide resolved
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Outdated
Show resolved
Hide resolved
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Outdated
Show resolved
Hide resolved
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Outdated
Show resolved
Hide resolved
|
||
// Enable kernel-space receive time measurement | ||
result = setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMP, &enable, sizeof(enable)); | ||
if (result < 0) throw SocketError(errno); |
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.
Very very nit: sock_fd
is checked for explicitly -1, where setsockopt
for < 0. Both seem to only return -1 when a problem has occurred.
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.
Addressed in 193bf6e.
* @brief Gracefully stops the active receiver thread (if any) but keeps the socket alive. The | ||
* same socket can later be subscribed again. | ||
*/ | ||
UdpSocket & unsubscribe() |
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.
If the socket is kept alive, should we consider shutting it down to prevent reading from it?
shutdown(sock_fd_, SHUT_RD);
and associated error handling.
|
||
~UdpSocket() | ||
{ | ||
unsubscribe(); |
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.
Would it be better to leave any subscribed multicast groups on destruction? (or in unsubscribe)
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Show resolved
Hide resolved
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Show resolved
Hide resolved
...a_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_common/connections/udp.hpp
Outdated
Show resolved
Hide resolved
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once |
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.
nit: are we moving to header blocks?
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.
Do you mean
#ifndef ...
#define ...
versus
#pragma once
?
I strongly prefer pragma once for style, is there any discussion on this I have missed?
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once |
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.
nit: are we moving to header blocks?
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.
(see my other comment on udp.hpp
)
int sock_fd_; | ||
pollfd poll_fd_; | ||
|
||
size_t buffer_size_ = 1500; |
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.
uniform initialization and const/constexpr for the 1500?
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.
It can be changed during runtime via set_mtu
, but I agree with uniform initialization.
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.
Addressed in 9ea3a90.
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
Signed-off-by: Max SCHMELLER <[email protected]>
PR Type
Description
The current Boost.ASIO/transport_drivers implementation is bloated and does not offer all the features we need for accurate timing and packet loss measurement.
Specifically, a good equivalent to
recvmsg
(seeman recvmsg
for details) is not supported.This PR introduces a new, minimal and robust UDP socket implementation with the following features:
SO_TIMESTAMP
(seeman 7 socket
)SO_RXQ_OVFL
(seeman 7 socket
)*: Depending on the network interface hardware, the timestamp will be measured in hardware on packet arrival, or by the kernel in software as soon as possible after. In any case, the timing is much more accurate than doing it in user space, where scheduling has a huge impact on accuracy.
Usage
I aimed to document the class as well as possible, but still, here is a quick rundown of how to use the socket:
Functions can also be chained like this:
auto sock = UdpSocket().init(...).bind().subscribe(...);
Pre-Review Checklist for the PR Author
PR Author should check the checkboxes below when creating the PR.
Checklist for the PR Reviewer
Reviewers should check the checkboxes below before approval.
Post-Review Checklist for the PR Author
PR Author should check the checkboxes below before merging.
CI Checks