code cleanup (put functionality in separate function to avoid copied code)
This commit is contained in:
parent
9feff9057a
commit
a6a6ffeda8
2 changed files with 19 additions and 6 deletions
|
@ -157,9 +157,8 @@ void CClient::OnNewConnection()
|
||||||
|
|
||||||
void CClient::OnReceivePingMessage ( int iMs )
|
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)
|
// 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 )
|
if ( iCurDiff >= 0 )
|
||||||
{
|
{
|
||||||
emit PingTimeReceived ( iCurDiff );
|
emit PingTimeReceived ( iCurDiff );
|
||||||
|
@ -168,15 +167,26 @@ void CClient::OnReceivePingMessage ( int iMs )
|
||||||
|
|
||||||
void CClient::OnCLPingReceived ( CHostAddress InetAddr, 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)
|
// 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 )
|
if ( iCurDiff >= 0 )
|
||||||
{
|
{
|
||||||
emit CLPingTimeReceived ( InetAddr, iCurDiff );
|
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 )
|
bool CClient::SetServerAddr ( QString strNAddr )
|
||||||
{
|
{
|
||||||
QHostAddress InetAddr;
|
QHostAddress InetAddr;
|
||||||
|
|
|
@ -210,10 +210,10 @@ public:
|
||||||
{ Channel.CreateChatTextMes ( strChatText ); }
|
{ Channel.CreateChatTextMes ( strChatText ); }
|
||||||
|
|
||||||
void SendPingMess()
|
void SendPingMess()
|
||||||
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
|
{ Channel.CreatePingMes ( PreparePingMessage() ); };
|
||||||
|
|
||||||
void SendCLPingMess ( const CHostAddress& InetAddr )
|
void SendCLPingMess ( const CHostAddress& InetAddr )
|
||||||
{ ConnLessChannel.CreateCLPingMes ( InetAddr, PreciseTime.elapsed() ); };
|
{ ConnLessChannel.CreateCLPingMes ( InetAddr, PreparePingMessage() ); };
|
||||||
|
|
||||||
int EstimatedOverallDelay ( const int iPingTimeMs );
|
int EstimatedOverallDelay ( const int iPingTimeMs );
|
||||||
|
|
||||||
|
@ -237,6 +237,9 @@ protected:
|
||||||
void ProcessAudioDataIntern ( CVector<short>& vecsStereoSndCrd );
|
void ProcessAudioDataIntern ( CVector<short>& vecsStereoSndCrd );
|
||||||
void UpdateSocketBufferSize();
|
void UpdateSocketBufferSize();
|
||||||
|
|
||||||
|
int PreparePingMessage();
|
||||||
|
int EvaluatePingMessage ( const int iMs );
|
||||||
|
|
||||||
// only one channel is needed for client application
|
// only one channel is needed for client application
|
||||||
CChannel Channel;
|
CChannel Channel;
|
||||||
CConnectionLessChannel ConnLessChannel;
|
CConnectionLessChannel ConnLessChannel;
|
||||||
|
|
Loading…
Reference in a new issue