From a6a6ffeda825605a122c44356f28f266d22d3183 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 30 Mar 2011 08:03:54 +0000 Subject: [PATCH] code cleanup (put functionality in separate function to avoid copied code) --- src/client.cpp | 18 ++++++++++++++---- src/client.h | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 54156578..72e854e2 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -157,9 +157,8 @@ void CClient::OnNewConnection() void CClient::OnReceivePingMessage ( int iMs ) { - // calculate difference between received time in ms and current time in ms, // take care of wrap arounds (if wrapping, do not use result) - const int iCurDiff = PreciseTime.elapsed() - iMs; + const int iCurDiff = EvaluatePingMessage ( iMs ); if ( iCurDiff >= 0 ) { emit PingTimeReceived ( iCurDiff ); @@ -168,15 +167,26 @@ void CClient::OnReceivePingMessage ( int iMs ) void CClient::OnCLPingReceived ( CHostAddress InetAddr, int iMs ) { - // calculate difference between received time in ms and current time in ms, // take care of wrap arounds (if wrapping, do not use result) - const int iCurDiff = PreciseTime.elapsed() - iMs; + const int iCurDiff = EvaluatePingMessage ( iMs ); if ( iCurDiff >= 0 ) { emit CLPingTimeReceived ( InetAddr, iCurDiff ); } } +int CClient::PreparePingMessage() +{ + // transmit the current precise time (in ms) + return PreciseTime.elapsed(); +} + +int CClient::EvaluatePingMessage ( const int iMs ) +{ + // calculate difference between received time in ms and current time in ms + return PreciseTime.elapsed() - iMs; +} + bool CClient::SetServerAddr ( QString strNAddr ) { QHostAddress InetAddr; diff --git a/src/client.h b/src/client.h index 4a4abef7..218ba2f8 100755 --- a/src/client.h +++ b/src/client.h @@ -210,10 +210,10 @@ public: { Channel.CreateChatTextMes ( strChatText ); } void SendPingMess() - { Channel.CreatePingMes ( PreciseTime.elapsed() ); }; + { Channel.CreatePingMes ( PreparePingMessage() ); }; void SendCLPingMess ( const CHostAddress& InetAddr ) - { ConnLessChannel.CreateCLPingMes ( InetAddr, PreciseTime.elapsed() ); }; + { ConnLessChannel.CreateCLPingMes ( InetAddr, PreparePingMessage() ); }; int EstimatedOverallDelay ( const int iPingTimeMs ); @@ -237,6 +237,9 @@ protected: void ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ); void UpdateSocketBufferSize(); + int PreparePingMessage(); + int EvaluatePingMessage ( const int iMs ); + // only one channel is needed for client application CChannel Channel; CConnectionLessChannel ConnLessChannel;