1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

Use proper function to read data from socket.

This commit is contained in:
Bartosz Taudul 2017-09-13 02:08:35 +02:00
parent 3dd744019a
commit f0d76af15c
2 changed files with 10 additions and 19 deletions

View File

@ -35,6 +35,11 @@ View::~View()
m_thread.join(); m_thread.join();
} }
bool View::ShouldExit()
{
return s_instance->m_shutdown.load( std::memory_order_relaxed );
}
void View::Worker() void View::Worker()
{ {
Socket sock; Socket sock;
@ -48,26 +53,10 @@ void View::Worker()
if( m_shutdown.load( std::memory_order_relaxed ) ) return; if( m_shutdown.load( std::memory_order_relaxed ) ) return;
if( !sock.Connect( m_addr.c_str(), "8086" ) ) continue; 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; uint8_t lz4;
while( sock.Recv( &lz4, 1, nullptr ) == -1 )
{ if( !sock.Read( &m_timeBegin, sizeof( m_timeBegin ), &tv, ShouldExit ) ) goto close;
if( m_shutdown.load( std::memory_order_relaxed ) ) return; if( !sock.Read( &lz4, sizeof( lz4 ), &tv, ShouldExit ) ) goto close;
}
for(;;) for(;;)
{ {

View File

@ -15,6 +15,8 @@ public:
View( const char* addr ); View( const char* addr );
~View(); ~View();
static bool ShouldExit();
private: private:
void Worker(); void Worker();