code cleanup (put functionality in separate function to avoid copied code)

This commit is contained in:
Volker Fischer 2011-03-30 08:03:54 +00:00
parent 9feff9057a
commit a6a6ffeda8
2 changed files with 19 additions and 6 deletions

View File

@ -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;

View File

@ -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<short>& vecsStereoSndCrd );
void UpdateSocketBufferSize();
int PreparePingMessage();
int EvaluatePingMessage ( const int iMs );
// only one channel is needed for client application
CChannel Channel;
CConnectionLessChannel ConnLessChannel;