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.
This commit is contained in:
@@ -22,7 +22,6 @@ UdpCommandDemuxer::UdpCommandDemuxer(
|
|||||||
)
|
)
|
||||||
: componentThread(componentThread), deviceManager(deviceManager),
|
: componentThread(componentThread), deviceManager(deviceManager),
|
||||||
commandPort(commandPort),
|
commandPort(commandPort),
|
||||||
timer(componentThread->getIoService()),
|
|
||||||
senderAddrLen(sizeof(senderAddr))
|
senderAddrLen(sizeof(senderAddr))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -50,12 +49,6 @@ void UdpCommandDemuxer::start()
|
|||||||
// Start the async receive loop
|
// Start the async receive loop
|
||||||
startAsyncReceive();
|
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
|
std::cout
|
||||||
<< __func__ << ": UDP Command Demuxer started on port "
|
<< __func__ << ": UDP Command Demuxer started on port "
|
||||||
<< commandPort << std::endl;
|
<< commandPort << std::endl;
|
||||||
@@ -77,9 +70,6 @@ void UdpCommandDemuxer::stop()
|
|||||||
|
|
||||||
shouldStop.store(true);
|
shouldStop.store(true);
|
||||||
|
|
||||||
// Cancel timer
|
|
||||||
timer.cancel();
|
|
||||||
|
|
||||||
// Close socket and cleanup
|
// Close socket and cleanup
|
||||||
if (cmdEndpointFdDesc)
|
if (cmdEndpointFdDesc)
|
||||||
{
|
{
|
||||||
@@ -198,31 +188,6 @@ void UdpCommandDemuxer::onDataReady(const boost::system::error_code &error)
|
|||||||
startAsyncReceive();
|
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()
|
void UdpCommandDemuxer::processIncomingData()
|
||||||
{
|
{
|
||||||
if (bytesReceived < 2)
|
if (bytesReceived < 2)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
|
|
||||||
@@ -57,7 +56,6 @@ private:
|
|||||||
void setupSocket();
|
void setupSocket();
|
||||||
void startAsyncReceive();
|
void startAsyncReceive();
|
||||||
void onDataReady(const boost::system::error_code& error);
|
void onDataReady(const boost::system::error_code& error);
|
||||||
void onTimerTick(const boost::system::error_code& error);
|
|
||||||
void processIncomingData();
|
void processIncomingData();
|
||||||
|
|
||||||
std::shared_ptr<smo::ComponentThread> componentThread;
|
std::shared_ptr<smo::ComponentThread> componentThread;
|
||||||
@@ -66,7 +64,6 @@ private:
|
|||||||
|
|
||||||
// Socket and async objects
|
// Socket and async objects
|
||||||
std::shared_ptr<boost::asio::posix::stream_descriptor> cmdEndpointFdDesc;
|
std::shared_ptr<boost::asio::posix::stream_descriptor> cmdEndpointFdDesc;
|
||||||
boost::asio::deadline_timer timer;
|
|
||||||
|
|
||||||
// State management
|
// State management
|
||||||
std::atomic<bool> isActive{false};
|
std::atomic<bool> isActive{false};
|
||||||
|
|||||||
Reference in New Issue
Block a user