Make View socket available to every method in class.

This commit is contained in:
Bartosz Taudul 2017-09-14 02:15:04 +02:00
parent ef7dca9073
commit b9c76f3452
2 changed files with 10 additions and 11 deletions

View File

@ -8,7 +8,6 @@
#include "../common/tracy_lz4.hpp"
#include "../common/TracyProtocol.hpp"
#include "../common/TracySocket.hpp"
#include "../common/TracySystem.hpp"
#include "../common/TracyQueue.hpp"
#include "TracyView.hpp"
@ -45,8 +44,6 @@ bool View::ShouldExit()
void View::Worker()
{
Socket sock;
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
@ -54,12 +51,12 @@ void View::Worker()
for(;;)
{
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
if( !sock.Connect( m_addr.c_str(), "8086" ) ) continue;
if( !m_sock.Connect( m_addr.c_str(), "8086" ) ) continue;
uint8_t lz4;
if( !sock.Read( &m_timeBegin, sizeof( m_timeBegin ), &tv, ShouldExit ) ) goto close;
if( !sock.Read( &lz4, sizeof( lz4 ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( &m_timeBegin, sizeof( m_timeBegin ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( &lz4, sizeof( lz4 ), &tv, ShouldExit ) ) goto close;
for(;;)
{
@ -70,8 +67,8 @@ void View::Worker()
char buf[TargetFrameSize];
char lz4buf[LZ4Size];
lz4sz_t lz4sz;
if( !sock.Read( &lz4sz, sizeof( lz4sz ), &tv, ShouldExit ) ) goto close;
if( !sock.Read( lz4buf, lz4sz, &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( &lz4sz, sizeof( lz4sz ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( lz4buf, lz4sz, &tv, ShouldExit ) ) goto close;
auto sz = LZ4_decompress_safe( lz4buf, buf, lz4sz, TargetFrameSize );
assert( sz >= 0 );
@ -88,14 +85,14 @@ void View::Worker()
else
{
QueueItem ev;
if( !sock.Read( &ev.hdr, sizeof( QueueHeader ), &tv, ShouldExit ) ) goto close;
if( !sock.Read( ((char*)&ev) + sizeof( QueueHeader ), QueueDataSize[ev.hdr.idx] - sizeof( QueueHeader ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( &ev.hdr, sizeof( QueueHeader ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( ((char*)&ev) + sizeof( QueueHeader ), QueueDataSize[ev.hdr.idx] - sizeof( QueueHeader ), &tv, ShouldExit ) ) goto close;
Process( ev );
}
}
close:
sock.Close();
m_sock.Close();
}
}

View File

@ -8,6 +8,7 @@
#include <unordered_map>
#include <vector>
#include "../common/TracySocket.hpp"
#include "../common/TracyQueue.hpp"
#include "TracyEvent.hpp"
@ -34,6 +35,7 @@ private:
std::string m_addr;
Socket m_sock;
std::thread m_thread;
std::atomic<bool> m_shutdown;