From c056f3be4143311ec116ba4b4573d177fb54363d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 10 Jul 2018 21:33:22 +0200 Subject: [PATCH] Send keep alive messages to determine if client disconnected. --- client/TracyProfiler.cpp | 25 +++++++++++++++++++++++-- server/TracyWorker.cpp | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index be4a769c..886aab23 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -286,6 +286,7 @@ void Profiler::Worker() m_sock->Send( &welcome, sizeof( welcome ) ); LZ4_resetStream( m_stream ); + int keepAlive = 0; for(;;) { const auto status = Dequeue( token ); @@ -297,8 +298,28 @@ void Profiler::Worker() else if( status == QueueEmpty && serialStatus == QueueEmpty ) { if( ShouldExit() ) break; - if( m_bufferOffset != m_bufferStart ) CommitData(); - std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + if( m_bufferOffset != m_bufferStart ) + { + if( !CommitData() ) break; + } + if( keepAlive == 500 ) + { + QueueItem ka; + ka.hdr.type = QueueType::KeepAlive; + AppendData( &ka, QueueDataSize[ka.hdr.idx] ); + if( !CommitData() ) break; + + keepAlive = 0; + } + else + { + keepAlive++; + std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + } + } + else + { + keepAlive = 0; } while( m_sock->HasData() ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 43b601b6..8ab74abe 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1639,6 +1639,8 @@ void Worker::Process( const QueueItem& ev ) case QueueType::Terminate: m_terminate = true; break; + case QueueType::KeepAlive: + break; default: assert( false ); break;