Handle incoming strings.

This commit is contained in:
Bartosz Taudul 2017-09-14 19:44:49 +02:00
parent bbbf52eafd
commit e8989d955c
2 changed files with 48 additions and 5 deletions

View File

@ -78,16 +78,19 @@ void View::Worker()
while( ptr < end )
{
auto ev = (QueueItem*)ptr;
Process( *ev );
ptr += QueueDataSize[ev->hdr.idx];
DispatchProcess( *ev, ptr );
}
}
else
{
QueueItem ev;
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 );
const auto payload = QueueDataSize[ev.hdr.idx] - sizeof( QueueHeader );
if( payload > 0 )
{
if( !m_sock.Read( ((char*)&ev) + sizeof( QueueHeader ), payload, &tv, ShouldExit ) ) goto close;
}
DispatchProcess( ev );
}
}
@ -96,6 +99,43 @@ close:
}
}
void View::DispatchProcess( const QueueItem& ev )
{
if( ev.hdr.type == QueueType::StringData )
{
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
char buf[TargetFrameSize];
uint16_t sz;
m_sock.Read( &sz, sizeof( sz ), &tv, ShouldExit );
m_sock.Read( buf, sz, &tv, ShouldExit );
AddString( ev.hdr.id, std::string( buf, buf+sz ) );
}
else
{
Process( ev );
}
}
void View::DispatchProcess( const QueueItem& ev, const char*& ptr )
{
ptr += QueueDataSize[ev.hdr.idx];
if( ev.hdr.type == QueueType::StringData )
{
uint16_t sz;
memcpy( &sz, ptr, sizeof( sz ) );
ptr += sizeof( sz );
AddString( ev.hdr.id, std::string( ptr, ptr+sz ) );
ptr += sz;
}
else
{
Process( ev );
}
}
void View::Process( const QueueItem& ev )
{
switch( ev.hdr.type )

View File

@ -29,8 +29,11 @@ public:
private:
void Worker();
void Process( const QueueItem& ev );
void DispatchProcess( const QueueItem& ev );
void DispatchProcess( const QueueItem& ev, const char*& ptr );
void Process( const QueueItem& ev );
void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev );
void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev );