Skip to content

Commit

Permalink
fix some sonar issues #sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Jun 21, 2024
1 parent 3c79838 commit 591cb10
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
31 changes: 17 additions & 14 deletions include/libcyphal/transport/can/can_transport_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ class TransportImpl final : private TransportDelegate, public ICanTransport //
///
CETL_NODISCARD cetl::optional<AnyError> runSingleMediaTransmit(Media& media, const TimePoint now)
{
while (const CanardTxQueueItem* const tx_item = ::canardTxPeek(&media.canard_tx_queue()))
for (const CanardTxQueueItem* tx_item = ::canardTxPeek(&media.canard_tx_queue()); tx_item != nullptr;
tx_item = ::canardTxPeek(&media.canard_tx_queue()))
{
// Prepare a lambda to pop and free the TX queue item, but not just yet.
// In case of media not being ready to push this item, we will need to retry it on next `run`.
Expand Down Expand Up @@ -624,25 +625,27 @@ class TransportImpl final : private TransportDelegate, public ICanTransport //

cetl::optional<AnyError> opt_any_error =
tryHandleTransientMediaError<TransientErrorReport::MediaPush>(media, std::move(*error));
if (!opt_any_error.has_value())
if (opt_any_error.has_value())
{
// The handler (if any) just said that it's fine to continue with pushing other frames
// and ignore such a transient media error (and don't propagate it outside).
continue;
return opt_any_error;
}

return opt_any_error;
// The handler just said that it's fine to continue with pushing other frames
// and ignore such a transient media error (and don't propagate it outside).
}
const auto is_pushed = cetl::get<bool>(maybe_pushed);
if (!is_pushed)
else
{
// Media interface is busy, so we are done with this media for now,
// and will just try again with it later (on next `run`).
// Note, we are NOT releasing this item from the queue, so it will be retried on next `run`.
break;
}
const auto is_pushed = cetl::get<bool>(maybe_pushed);
if (!is_pushed)
{
// Media interface is busy, so we are done with this media for now,
// and will just try again with it later (on next `run`).
// Note, we are NOT releasing this item from the queue, so it will be retried on next `run`.
break;
}

popAndFreeCanardTxQueueItem();
popAndFreeCanardTxQueueItem();
}

} // for each frame

Expand Down
35 changes: 19 additions & 16 deletions include/libcyphal/transport/udp/udp_transport_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ class TransportImpl final : private TransportDelegate, public IUdpTransport //
{
using PayloadFragment = cetl::span<const cetl::byte>;

while (const UdpardTxItem* const tx_item = ::udpardTxPeek(&media.udpard_tx()))
for (const UdpardTxItem* tx_item = ::udpardTxPeek(&media.udpard_tx()); tx_item != nullptr;
tx_item = ::udpardTxPeek(&media.udpard_tx()))
{
// Prepare a lambda to pop and free the TX queue item, but not just yet.
// In case of socket not being ready to send this item, we will need to retry it on next `run`.
Expand Down Expand Up @@ -646,28 +647,30 @@ class TransportImpl final : private TransportDelegate, public IUdpTransport //
tryHandleTransientMediaError<TransientErrorReport::MediaTxSocketSend>(media,
std::move(*error),
tx_socket);
if (!opt_any_error.has_value())
if (opt_any_error.has_value())
{
// The handler (if any) just said that it's fine to continue with sending other frames
// and ignore such a transient media error (and don't propagate it outside).
continue;
return opt_any_error;
}

return opt_any_error;
// The handler just said that it's fine to continue with sending other frames
// and ignore such a transient media error (and don't propagate it outside).
}
const auto is_sent = cetl::get<bool>(maybe_sent);
if (!is_sent)
else
{
// TX socket interface is busy, so we are done with this media for now,
// and will just try again with it later (on next `run`).
// Note, we are NOT releasing this item from the queue, so it will be retried on next `run`.
break;
const auto is_sent = cetl::get<bool>(maybe_sent);
if (!is_sent)
{
// TX socket interface is busy, so we are done with this media for now,
// and will just try again with it later (on next `run`).
// Note, we are NOT releasing this item from the queue, so it will be retried on next `run`.
break;

// TODO: It seems that `Multiplexer` interface would be used here
// but it is not yet implemented, so for now just `break`.
}
// TODO: It seems that `Multiplexer` interface would be used here
// but it is not yet implemented, so for now just `break`.
}

popAndFreeUdpardTxItem();
popAndFreeUdpardTxItem();
}

} // for each frame

Expand Down

0 comments on commit 591cb10

Please sign in to comment.