From 174eb0d1cde855396461413431611bb662af9e67 Mon Sep 17 00:00:00 2001 From: Sean Mollet Date: Fri, 27 Sep 2024 10:19:40 -0500 Subject: [PATCH 1/2] Add a delay to shutdown after the socket closes to give time for processing received packets --- src/impl/tcptransport.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/impl/tcptransport.cpp b/src/impl/tcptransport.cpp index a83fda958..52ee44c21 100644 --- a/src/impl/tcptransport.cpp +++ b/src/impl/tcptransport.cpp @@ -462,6 +462,11 @@ void TcpTransport::process(PollService::Event event) { PLOG_ERROR << e.what(); } + // Allow any received messages to be processed before we shut down and destroy the callbacks + // This should probably be a mutex or check of a queue size or something, but I can't figure out + // what to do that against and a 100ms delay seems to be plenty + + usleep(100 * 1000); PLOG_INFO << "TCP disconnected"; PollService::Instance().remove(mSock); changeState(State::Disconnected); From 6ac6d166ecfa22ca0e2e89bca6aa16d3ac28f012 Mon Sep 17 00:00:00 2001 From: Sean Mollet Date: Fri, 27 Sep 2024 10:54:35 -0500 Subject: [PATCH 2/2] Use a cross platform sleep --- src/impl/tcptransport.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/impl/tcptransport.cpp b/src/impl/tcptransport.cpp index 52ee44c21..bd9428cb3 100644 --- a/src/impl/tcptransport.cpp +++ b/src/impl/tcptransport.cpp @@ -465,8 +465,7 @@ void TcpTransport::process(PollService::Event event) { // Allow any received messages to be processed before we shut down and destroy the callbacks // This should probably be a mutex or check of a queue size or something, but I can't figure out // what to do that against and a 100ms delay seems to be plenty - - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); PLOG_INFO << "TCP disconnected"; PollService::Instance().remove(mSock); changeState(State::Disconnected);