Allow specifying network port in server.

This commit is contained in:
Bartosz Taudul 2019-09-21 15:43:01 +02:00
parent fb63dd89bc
commit 82cd667b30
10 changed files with 58 additions and 23 deletions

View File

@ -30,7 +30,7 @@ void SigInt( int )
void Usage()
{
printf( "Usage: capture -a address -o output.tracy\n" );
printf( "Usage: capture -a address -o output.tracy [-p port]\n" );
exit( 1 );
}
@ -46,9 +46,10 @@ int main( int argc, char** argv )
const char* address = nullptr;
const char* output = nullptr;
int port = 8086;
int c;
while( ( c = getopt( argc, argv, "a:o:" ) ) != -1 )
while( ( c = getopt( argc, argv, "a:o:p:" ) ) != -1 )
{
switch( c )
{
@ -58,6 +59,9 @@ int main( int argc, char** argv )
case 'o':
output = optarg;
break;
case 'p':
port = atoi( optarg );
break;
default:
Usage();
break;
@ -66,9 +70,9 @@ int main( int argc, char** argv )
if( !address || !output ) Usage();
printf( "Connecting to %s...", address );
printf( "Connecting to %s:%i...", address, port );
fflush( stdout );
tracy::Worker worker( address );
tracy::Worker worker( address, port );
while( !worker.IsConnected() )
{
const auto handshake = worker.GetHandshakeStatus();

View File

@ -86,7 +86,7 @@ Socket::~Socket()
}
}
bool Socket::Connect( const char* addr, const char* port )
bool Socket::Connect( const char* addr, int port )
{
assert( m_sock == -1 );
@ -97,7 +97,10 @@ bool Socket::Connect( const char* addr, const char* port )
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if( getaddrinfo( addr, port, &hints, &res ) != 0 ) return false;
char portbuf[32];
sprintf( portbuf, "%i", port );
if( getaddrinfo( addr, portbuf, &hints, &res ) != 0 ) return false;
int sock = 0;
for( ptr = res; ptr; ptr = ptr->ai_next )
{

View File

@ -21,7 +21,7 @@ public:
Socket( int sock );
~Socket();
bool Connect( const char* addr, const char* port );
bool Connect( const char* addr, int port );
void Close();
int Send( const void* buf, int len );

View File

@ -8,8 +8,9 @@
#include "ResolvService.hpp"
ResolvService::ResolvService()
ResolvService::ResolvService( int port )
: m_exit( false )
, m_port( port )
, m_thread( [this] { Worker(); } )
{
}
@ -32,7 +33,7 @@ void ResolvService::Worker()
{
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_port = 8086;
addr.sin_port = m_port;
char buf[128];

View File

@ -19,7 +19,7 @@ class ResolvService
};
public:
ResolvService();
ResolvService( int port );
~ResolvService();
void Query( uint32_t ip, const std::function<void(std::string&&)>& callback );
@ -31,6 +31,7 @@ private:
std::mutex m_lock;
std::condition_variable m_cv;
std::vector<QueueItem> m_queue;
int m_port;
std::thread m_thread;
};

View File

@ -104,6 +104,9 @@ int main( int argc, char** argv )
std::unique_ptr<tracy::View> view;
tracy::BadVersionState badVer;
int port = 8086;
const char* connectTo = nullptr;
if( argc == 2 )
{
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( argv[1] ) );
@ -112,9 +115,30 @@ int main( int argc, char** argv )
view = std::make_unique<tracy::View>( *f );
}
}
else if( argc == 3 && strcmp( argv[1], "-a" ) == 0 )
else
{
view = std::make_unique<tracy::View>( argv[2] );
while( argc >= 3 )
{
if( strcmp( argv[1], "-a" ) == 0 )
{
connectTo = argv[2];
}
else if( strcmp( argv[1], "-p" ) == 0 )
{
port = atoi( argv[2] );
}
else
{
fprintf( stderr, "Bad parameter: %s", argv[1] );
exit( 1 );
}
argc -= 2;
argv += 2;
}
}
if( connectTo )
{
view = std::make_unique<tracy::View>( connectTo, port );
}
char title[128];
@ -261,7 +285,7 @@ int main( int argc, char** argv )
std::mutex resolvLock;
tracy::flat_hash_map<std::string, std::string> resolvMap;
ResolvService resolv;
ResolvService resolv( port );
glfwShowWindow( window );
@ -296,7 +320,7 @@ int main( int argc, char** argv )
if( !broadcastListen )
{
broadcastListen = std::make_unique<tracy::UdpListen>();
if( !broadcastListen->Listen( 8086 ) )
if( !broadcastListen->Listen( port ) )
{
broadcastListen.reset();
}
@ -456,7 +480,7 @@ int main( int argc, char** argv )
}
connHistVec = RebuildConnectionHistory( connHistMap );
view = std::make_unique<tracy::View>( addr, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
}
ImGui::SameLine( 0, ImGui::GetFontSize() * 2 );
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
@ -527,7 +551,7 @@ int main( int argc, char** argv )
if( badProto ) flags |= ImGuiSelectableFlags_Disabled;
if( ImGui::Selectable( name->second.c_str(), &sel, flags ) && !loadThread.joinable() )
{
view = std::make_unique<tracy::View>( v.second.address.c_str(), fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( v.second.address.c_str(), port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
}
ImGui::NextColumn();
const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll;

View File

@ -110,8 +110,8 @@ enum { MinFrameSize = 5 };
static View* s_instance = nullptr;
View::View( const char* addr, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb )
: m_worker( addr )
View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb )
: m_worker( addr, port )
, m_staticView( false )
, m_pause( false )
, m_frames( nullptr )

View File

@ -63,8 +63,8 @@ public:
using SetTitleCallback = void(*)( const char* );
View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, smallFont, bigFont, stcb ) {}
View( const char* addr, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr );
View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb ) {}
View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr );
~View();

View File

@ -234,8 +234,9 @@ static tracy_force_inline void UpdateLockRange( LockMap& lockmap, const LockEven
LoadProgress Worker::s_loadProgress;
Worker::Worker( const char* addr )
Worker::Worker( const char* addr, int port )
: m_addr( addr )
, m_port( port )
, m_hasData( false )
, m_stream( LZ4_createStreamDecode() )
, m_buffer( new char[TargetFrameSize*3 + 1] )
@ -2125,7 +2126,7 @@ void Worker::Exec()
for(;;)
{
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break;
if( m_sock.Connect( m_addr.c_str(), m_port ) ) break;
}
auto lz4buf = std::make_unique<char[]>( LZ4Size );

View File

@ -270,7 +270,7 @@ public:
NUM_FAILURES
};
Worker( const char* addr );
Worker( const char* addr, int port );
Worker( FileRead& f, EventType::Type eventMask = EventType::All );
~Worker();
@ -536,6 +536,7 @@ private:
Socket m_sock;
std::string m_addr;
int m_port;
std::thread m_thread;
std::atomic<bool> m_connected { false };