From 9ea7700bde128f2601d5b7d8849e96c0a08e15c6 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Thu, 17 Oct 2019 14:02:44 +0100 Subject: IVGCVSW-3409 Create the ProfilingService class * Improve the error handling in SocketProfilingConnection to close the socket when an error has been detected. * Update the CommandHandler thread to handle a closed socket. Signed-off-by: Colm Donelan Change-Id: I1577c8d7d57a7af9bde98c2dec12cb19a3afb21d --- src/profiling/CommandHandler.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/profiling/CommandHandler.cpp') diff --git a/src/profiling/CommandHandler.cpp b/src/profiling/CommandHandler.cpp index cc68dcf74d..b0603b0ed5 100644 --- a/src/profiling/CommandHandler.cpp +++ b/src/profiling/CommandHandler.cpp @@ -4,6 +4,7 @@ // #include "CommandHandler.hpp" +#include "ProfilingService.hpp" #include @@ -20,6 +21,11 @@ void CommandHandler::Start(IProfilingConnection& profilingConnection) return; } + if (m_CommandThread.joinable()) + { + m_CommandThread.join(); + } + m_IsRunning.store(true); m_KeepRunning.store(true); m_CommandThread = std::thread(&CommandHandler::HandleCommands, this, std::ref(profilingConnection)); @@ -67,6 +73,14 @@ void CommandHandler::HandleCommands(IProfilingConnection& profilingConnection) { // Log the error and continue BOOST_LOG_TRIVIAL(warning) << "An error has occurred when handling a command: " << e.what() << std::endl; + // Did we get here because the socket failed? + if ( !profilingConnection.IsOpen() ) + { + // We're going to stop processing commands. + // This will leave the thread idle. There is no mechanism to restart the profiling service when the + // connection is lost. + m_KeepRunning.store(false); + } } } while (m_KeepRunning.load()); -- cgit v1.2.1