Rework client handling of server requests.

This commit is contained in:
Bartosz Taudul 2017-09-22 01:54:04 +02:00
parent 0f99705243
commit 70ad3407c0
3 changed files with 35 additions and 11 deletions

View File

@ -115,10 +115,6 @@ void Profiler::Worker()
{
enum { BulkSize = TargetFrameSize / QueueItemSize };
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
moodycamel::ConsumerToken token( s_queue );
ListenSocket listen;
@ -172,9 +168,7 @@ void Profiler::Worker()
while( m_sock->HasData() )
{
uint64_t ptr;
if( !m_sock->Read( &ptr, sizeof( ptr ), &tv, ShouldExit ) ) break;
SendString( ptr );
if( !HandleServerQuery() ) break;
}
}
}
@ -193,12 +187,12 @@ bool Profiler::SendData( const char* data, size_t len )
return true;
}
bool Profiler::SendString( uint64_t str )
bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type )
{
auto ptr = (const char*)str;
assert( type == QueueType::StringData );
QueueHeader hdr;
hdr.type = QueueType::StringData;
hdr.type = type;
hdr.id = str;
auto buf = m_buffer + m_bufferOffset;
@ -217,4 +211,29 @@ bool Profiler::SendString( uint64_t str )
return SendData( buf, sizeof( hdr ) + sizeof( l16 ) + l16 );
}
bool Profiler::HandleServerQuery()
{
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
uint8_t type;
if( !m_sock->Read( &type, sizeof( type ), &tv, ShouldExit ) ) return false;
uint64_t ptr;
if( !m_sock->Read( &ptr, sizeof( ptr ), &tv, ShouldExit ) ) return false;
switch( type )
{
case ServerQueryString:
SendString( ptr, (const char*)ptr, QueueType::StringData );
break;
default:
assert( false );
break;
}
return true;
}
}

View File

@ -37,7 +37,9 @@ private:
void Worker();
bool SendData( const char* data, size_t len );
bool SendString( uint64_t ptr );
bool SendString( uint64_t ptr, const char* str, QueueType type );
bool HandleServerQuery();
int64_t m_timeBegin;
std::thread m_thread;

View File

@ -290,6 +290,9 @@ void View::CheckString( uint64_t ptr )
if( m_pendingStrings.find( ptr ) != m_pendingStrings.end() ) return;
m_pendingStrings.emplace( ptr );
uint8_t type = ServerQueryString;
m_sock.Send( &type, sizeof( type ) );
m_sock.Send( &ptr, sizeof( ptr ) );
}