UDP broadcast loop.

This commit is contained in:
Bartosz Taudul 2019-06-17 02:25:09 +02:00
parent 40e517594b
commit e609c0fdce
2 changed files with 31 additions and 0 deletions

View File

@ -920,6 +920,7 @@ Profiler::Profiler()
, m_shutdownManual( false ) , m_shutdownManual( false )
, m_shutdownFinished( false ) , m_shutdownFinished( false )
, m_sock( nullptr ) , m_sock( nullptr )
, m_broadcast( nullptr )
, m_noExit( false ) , m_noExit( false )
, m_zoneId( 1 ) , m_zoneId( 1 )
, m_stream( LZ4_createStream() ) , m_stream( LZ4_createStream() )
@ -1016,6 +1017,12 @@ Profiler::~Profiler()
tracy_free( m_sock ); tracy_free( m_sock );
} }
if( m_broadcast )
{
m_broadcast->~UdpBroadcast();
tracy_free( m_broadcast );
}
assert( s_instance ); assert( s_instance );
s_instance = nullptr; s_instance = nullptr;
} }
@ -1084,6 +1091,15 @@ void Profiler::Worker()
} }
} }
m_broadcast = (UdpBroadcast*)tracy_malloc( sizeof( UdpBroadcast ) );
new(m_broadcast) UdpBroadcast();
if( !m_broadcast->Open( "255.255.255.255", "8087" ) )
{
m_broadcast->~UdpBroadcast();
tracy_free( m_broadcast );
m_broadcast = nullptr;
}
// Connections loop. // Connections loop.
// Each iteration of the loop handles whole connection. Multiple iterations will only // Each iteration of the loop handles whole connection. Multiple iterations will only
// happen in the on-demand mode or when handshake fails. // happen in the on-demand mode or when handshake fails.
@ -1104,6 +1120,17 @@ void Profiler::Worker()
#ifndef TRACY_ON_DEMAND #ifndef TRACY_ON_DEMAND
ProcessSysTime(); ProcessSysTime();
#endif #endif
if( m_broadcast )
{
auto t = std::chrono::high_resolution_clock::now().time_since_epoch().count();
if( t - m_lastBroadcast > 5000000000 ) // 5s
{
m_lastBroadcast = t;
m_broadcast->Send( "abc", 3 );
auto err = WSAGetLastError();
}
}
} }
// Handshake // Handshake

View File

@ -47,6 +47,7 @@ namespace tracy
class GpuCtx; class GpuCtx;
class Profiler; class Profiler;
class Socket; class Socket;
class UdpBroadcast;
struct GpuCtxWrapper struct GpuCtxWrapper
{ {
@ -516,6 +517,7 @@ private:
std::atomic<bool> m_shutdownManual; std::atomic<bool> m_shutdownManual;
std::atomic<bool> m_shutdownFinished; std::atomic<bool> m_shutdownFinished;
Socket* m_sock; Socket* m_sock;
UdpBroadcast* m_broadcast;
bool m_noExit; bool m_noExit;
std::atomic<uint32_t> m_zoneId; std::atomic<uint32_t> m_zoneId;
@ -550,6 +552,8 @@ private:
#else #else
void ProcessSysTime() {} void ProcessSysTime() {}
#endif #endif
uint64_t m_lastBroadcast = 0;
}; };
}; };