From b65b0f23707f3f23e976d539aef1fcc76b46a616 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Fri, 31 Oct 2025 07:46:33 -0400 Subject: [PATCH] UdpCmdDemux: remove stop-"responsiveness" timer I think it's best to remove the timer tick from UdpCommandDemuxer. I looked at it again and it doesn't actually help with responsiveness. Whatever it contributes is no different from what stop() does. They both just call timer.cancel and cmdsocket.cancel. So if that doesn't stop the socket in stop(), it won't magically stop it more effectively if I call it from a timer handler. --- commonLibs/livoxProto1/udpCommandDemuxer.cpp | 35 -------------------- commonLibs/livoxProto1/udpCommandDemuxer.h | 3 -- 2 files changed, 38 deletions(-) diff --git a/commonLibs/livoxProto1/udpCommandDemuxer.cpp b/commonLibs/livoxProto1/udpCommandDemuxer.cpp index 1bbe0f0..5f656d9 100644 --- a/commonLibs/livoxProto1/udpCommandDemuxer.cpp +++ b/commonLibs/livoxProto1/udpCommandDemuxer.cpp @@ -22,7 +22,6 @@ UdpCommandDemuxer::UdpCommandDemuxer( ) : componentThread(componentThread), deviceManager(deviceManager), commandPort(commandPort), -timer(componentThread->getIoService()), senderAddrLen(sizeof(senderAddr)) { } @@ -50,12 +49,6 @@ void UdpCommandDemuxer::start() // Start the async receive loop startAsyncReceive(); - // Start the timer for responsiveness to stop() - timer.expires_from_now(boost::posix_time::milliseconds(1000)); - timer.async_wait( - std::bind( - &UdpCommandDemuxer::onTimerTick, this, std::placeholders::_1)); - std::cout << __func__ << ": UDP Command Demuxer started on port " << commandPort << std::endl; @@ -77,9 +70,6 @@ void UdpCommandDemuxer::stop() shouldStop.store(true); - // Cancel timer - timer.cancel(); - // Close socket and cleanup if (cmdEndpointFdDesc) { @@ -198,31 +188,6 @@ void UdpCommandDemuxer::onDataReady(const boost::system::error_code &error) startAsyncReceive(); } -void UdpCommandDemuxer::onTimerTick(const boost::system::error_code &error) -{ - if (error == boost::asio::error::operation_aborted) - { return; } - - if (shouldStop.load()) - { - // Stop was called, cancel async operations and stop timer - if (cmdEndpointFdDesc) { - cmdEndpointFdDesc->cancel(); - } - timer.cancel(); - return; - } - - // Re-arm timer for next tick - if (isActive.load()) - { - timer.expires_from_now(boost::posix_time::milliseconds(1000)); - timer.async_wait( - std::bind( - &UdpCommandDemuxer::onTimerTick, this, std::placeholders::_1)); - } -} - void UdpCommandDemuxer::processIncomingData() { if (bytesReceived < 2) diff --git a/commonLibs/livoxProto1/udpCommandDemuxer.h b/commonLibs/livoxProto1/udpCommandDemuxer.h index 078f407..7f44b1c 100644 --- a/commonLibs/livoxProto1/udpCommandDemuxer.h +++ b/commonLibs/livoxProto1/udpCommandDemuxer.h @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -57,7 +56,6 @@ private: void setupSocket(); void startAsyncReceive(); void onDataReady(const boost::system::error_code& error); - void onTimerTick(const boost::system::error_code& error); void processIncomingData(); std::shared_ptr componentThread; @@ -66,7 +64,6 @@ private: // Socket and async objects std::shared_ptr cmdEndpointFdDesc; - boost::asio::deadline_timer timer; // State management std::atomic isActive{false};