Non-on-demand client is only able to handle one connection.

This commit is contained in:
Bartosz Taudul 2018-09-09 19:42:06 +02:00
parent 984a711666
commit 9211ce42da
5 changed files with 85 additions and 0 deletions

View File

@ -147,6 +147,11 @@ int main( int argc, char** argv )
printf( "\nThe client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server.\n" ); printf( "\nThe client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server.\n" );
return 1; return 1;
} }
if( handshake == tracy::HandshakeNotAvailable )
{
printf( "\nThe client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled.\n" );
return 2;
}
} }
while( !worker.HasData() ) std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); while( !worker.HasData() ) std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
printf( "\nQueue delay: %s\nTimer resolution: %s\n", TimeToString( worker.GetDelay() ), TimeToString( worker.GetResolution() ) ); printf( "\nQueue delay: %s\nTimer resolution: %s\n", TimeToString( worker.GetDelay() ), TimeToString( worker.GetResolution() ) );

View File

@ -1021,6 +1021,64 @@ void Profiler::Worker()
m_sock->~Socket(); m_sock->~Socket();
tracy_free( m_sock ); tracy_free( m_sock );
// Client is no longer available here
for(;;)
{
if( ShouldExit() )
{
m_shutdownFinished.store( true, std::memory_order_relaxed );
return;
}
while( s_queue.try_dequeue_bulk( token, m_itemBuf, BulkSize ) > 0 ) {}
bool lockHeld = true;
while( !m_serialLock.try_lock() )
{
if( m_shutdownManual.load( std::memory_order_relaxed ) )
{
lockHeld = false;
break;
}
}
m_serialQueue.swap( m_serialDequeue );
if( lockHeld )
{
m_serialLock.unlock();
}
m_serialDequeue.clear();
m_sock = listen.Accept();
if( m_sock )
{
timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
char shibboleth[HandshakeShibbolethSize];
auto res = m_sock->ReadRaw( shibboleth, HandshakeShibbolethSize, &tv );
if( !res || memcmp( shibboleth, HandshakeShibboleth, HandshakeShibbolethSize ) != 0 )
{
m_sock->~Socket();
tracy_free( m_sock );
continue;
}
uint32_t protocolVersion;
res = m_sock->ReadRaw( &protocolVersion, sizeof( protocolVersion ), &tv );
if( !res )
{
m_sock->~Socket();
tracy_free( m_sock );
continue;
}
HandshakeStatus status = HandshakeNotAvailable;
m_sock->Send( &status, sizeof( status ) );
m_sock->~Socket();
tracy_free( m_sock );
}
}
} }
for(;;) for(;;)

View File

@ -37,6 +37,7 @@ enum HandshakeStatus : uint8_t
HandshakePending, HandshakePending,
HandshakeWelcome, HandshakeWelcome,
HandshakeProtocolMismatch, HandshakeProtocolMismatch,
HandshakeNotAvailable
}; };
enum { WelcomeMessageProgramNameSize = 64 }; enum { WelcomeMessageProgramNameSize = 64 };

View File

@ -460,6 +460,10 @@ bool View::Draw()
{ {
ImGui::OpenPopup( "Protocol mismatch" ); ImGui::OpenPopup( "Protocol mismatch" );
} }
else if( status == HandshakeNotAvailable )
{
ImGui::OpenPopup( "Client not ready" );
}
if( ImGui::BeginPopupModal( "Protocol mismatch", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) if( ImGui::BeginPopupModal( "Protocol mismatch", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{ {
@ -477,6 +481,22 @@ bool View::Draw()
ImGui::EndPopup(); ImGui::EndPopup();
} }
if( ImGui::BeginPopupModal( "Client not ready", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
#ifdef TRACY_EXTENDED_FONT
TextCentered( ICON_FA_LIGHTBULB );
#endif
ImGui::Text( "The client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled." );
ImGui::Separator();
if( ImGui::Button( "I understand" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
return false;
}
ImGui::EndPopup();
}
return s_instance->DrawImpl(); return s_instance->DrawImpl();
} }

View File

@ -1299,6 +1299,7 @@ void Worker::Exec()
case HandshakeWelcome: case HandshakeWelcome:
break; break;
case HandshakeProtocolMismatch: case HandshakeProtocolMismatch:
case HandshakeNotAvailable:
default: default:
goto close; goto close;
} }