From f0d76af15cd49ffcb1ca41850d415bb1d4f21117 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 13 Sep 2017 02:08:35 +0200 Subject: [PATCH] Use proper function to read data from socket. --- server/TracyView.cpp | 27 ++++++++------------------- server/TracyView.hpp | 2 ++ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 709ae984..1568b54d 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -35,6 +35,11 @@ View::~View() m_thread.join(); } +bool View::ShouldExit() +{ + return s_instance->m_shutdown.load( std::memory_order_relaxed ); +} + void View::Worker() { Socket sock; @@ -48,26 +53,10 @@ void View::Worker() if( m_shutdown.load( std::memory_order_relaxed ) ) return; if( !sock.Connect( m_addr.c_str(), "8086" ) ) continue; - auto left = sizeof( m_timeBegin ); - auto ptr = (char*)&m_timeBegin; - do - { - if( m_shutdown.load( std::memory_order_relaxed ) ) return; - auto sz = sock.Recv( ptr, left, &tv ); - if( sz == 0 ) goto close; - if( sz > 0 ) - { - left -= sz; - ptr += sz; - } - } - while( left > 0 ); - uint8_t lz4; - while( sock.Recv( &lz4, 1, nullptr ) == -1 ) - { - if( m_shutdown.load( std::memory_order_relaxed ) ) return; - } + + if( !sock.Read( &m_timeBegin, sizeof( m_timeBegin ), &tv, ShouldExit ) ) goto close; + if( !sock.Read( &lz4, sizeof( lz4 ), &tv, ShouldExit ) ) goto close; for(;;) { diff --git a/server/TracyView.hpp b/server/TracyView.hpp index a2ec514b..46667237 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -15,6 +15,8 @@ public: View( const char* addr ); ~View(); + static bool ShouldExit(); + private: void Worker();