diff --git a/src/channel.cpp b/src/channel.cpp index 2b8b7a1b..7d9da618 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -80,12 +80,12 @@ CChannelSet::CChannelSet() : bWriteStatusHTMLFile ( false ) QObject::connect ( &vecChannels[5], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh5 ( QString ) ) ); // ping message received - QObject::connect ( &vecChannels[0], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh0 ( QTime ) ) ); - QObject::connect ( &vecChannels[1], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh1 ( QTime ) ) ); - QObject::connect ( &vecChannels[2], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh2 ( QTime ) ) ); - QObject::connect ( &vecChannels[3], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh3 ( QTime ) ) ); - QObject::connect ( &vecChannels[4], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh4 ( QTime ) ) ); - QObject::connect ( &vecChannels[5], SIGNAL ( PingReceived ( QTime ) ), this, SLOT ( OnPingReceivedCh5 ( QTime ) ) ); + QObject::connect ( &vecChannels[0], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh0 ( int ) ) ); + QObject::connect ( &vecChannels[1], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh1 ( int ) ) ); + QObject::connect ( &vecChannels[2], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh2 ( int ) ) ); + QObject::connect ( &vecChannels[3], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh3 ( int ) ) ); + QObject::connect ( &vecChannels[4], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh4 ( int ) ) ); + QObject::connect ( &vecChannels[5], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh5 ( int ) ) ); } CVector CChannelSet::CreateChannelList() @@ -605,8 +605,8 @@ CChannel::CChannel() : sName ( "" ), QObject::connect( &Protocol, SIGNAL ( ChatTextReceived ( QString ) ), this, SIGNAL ( ChatTextReceived ( QString ) ) ); - QObject::connect( &Protocol, SIGNAL ( PingReceived ( QTime ) ), - this, SIGNAL ( PingReceived ( QTime ) ) ); + QObject::connect( &Protocol, SIGNAL ( PingReceived ( int ) ), + this, SIGNAL ( PingReceived ( int ) ) ); } void CChannel::SetEnable ( const bool bNEnStat ) diff --git a/src/channel.h b/src/channel.h index 5e80365c..1be02b2a 100755 --- a/src/channel.h +++ b/src/channel.h @@ -123,7 +123,7 @@ public: void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); } - void CreatePingMes ( const QTime time ) { Protocol.CreatePingMes ( time ); } + void CreatePingMes ( const int iMs ) { Protocol.CreatePingMes ( iMs ); } void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) { @@ -203,7 +203,7 @@ signals: void ProtocolStatus ( bool bOk ); void NameHasChanged(); void ChatTextReceived ( QString strChatText ); - void PingReceived ( QTime time ); + void PingReceived ( int iMs ); }; @@ -304,12 +304,12 @@ public slots: void OnChatTextReceivedCh4 ( QString strChatText ) { CreateAndSendChatTextForAllConChannels ( 4, strChatText ); } void OnChatTextReceivedCh5 ( QString strChatText ) { CreateAndSendChatTextForAllConChannels ( 5, strChatText ); } - void OnPingReceivedCh0 ( QTime time ) { vecChannels[0].CreatePingMes ( time ); } - void OnPingReceivedCh1 ( QTime time ) { vecChannels[1].CreatePingMes ( time ); } - void OnPingReceivedCh2 ( QTime time ) { vecChannels[2].CreatePingMes ( time ); } - void OnPingReceivedCh3 ( QTime time ) { vecChannels[3].CreatePingMes ( time ); } - void OnPingReceivedCh4 ( QTime time ) { vecChannels[4].CreatePingMes ( time ); } - void OnPingReceivedCh5 ( QTime time ) { vecChannels[5].CreatePingMes ( time ); } + void OnPingReceivedCh0 ( int iMs ) { vecChannels[0].CreatePingMes ( iMs ); } + void OnPingReceivedCh1 ( int iMs ) { vecChannels[1].CreatePingMes ( iMs ); } + void OnPingReceivedCh2 ( int iMs ) { vecChannels[2].CreatePingMes ( iMs ); } + void OnPingReceivedCh3 ( int iMs ) { vecChannels[3].CreatePingMes ( iMs ); } + void OnPingReceivedCh4 ( int iMs ) { vecChannels[4].CreatePingMes ( iMs ); } + void OnPingReceivedCh5 ( int iMs ) { vecChannels[5].CreatePingMes ( iMs ); } signals: void MessReadyForSending ( int iChID, CVector vecMessage ); diff --git a/src/client.cpp b/src/client.cpp index 84a56d2e..8a765ebc 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -55,8 +55,8 @@ CClient::CClient() : bRun ( false ), Socket ( &Channel ), QObject::connect ( &Channel, SIGNAL ( ChatTextReceived ( QString ) ), this, SIGNAL ( ChatTextReceived ( QString ) ) ); - QObject::connect ( &Channel, SIGNAL ( PingReceived ( QTime ) ), - this, SLOT ( OnReceivePingMessage ( QTime ) ) ); + QObject::connect ( &Channel, SIGNAL ( PingReceived ( int ) ), + this, SLOT ( OnReceivePingMessage ( int ) ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) @@ -97,10 +97,10 @@ void CClient::OnNewConnection() Channel.CreateReqConnClientsList(); } -void CClient::OnReceivePingMessage ( QTime time ) +void CClient::OnReceivePingMessage ( int iMs ) { - // calculate difference between received time and current time - emit PingTimeReceived ( time.msecsTo ( QTime().currentTime() ) /* ms */ ); + // calculate difference between received time in ms and current time in ms + emit PingTimeReceived ( CPreciseTime().elapsed() - iMs ); } bool CClient::SetServerAddr ( QString strNAddr ) diff --git a/src/client.h b/src/client.h index d2fd026e..6ee9a6c3 100755 --- a/src/client.h +++ b/src/client.h @@ -127,7 +127,7 @@ public: { Channel.CreateChatTextMes ( strChatText ); } void SendPingMess() - { Channel.CreatePingMes ( QTime().currentTime() ); } + { Channel.CreatePingMes ( CPreciseTime().elapsed() ); }; CSound* GetSndInterface() { return &Sound; } CChannel* GetChannel() { return &Channel; } @@ -187,7 +187,7 @@ public slots: void OnReqJittBufSize(); void OnProtocolStatus ( bool bOk ); void OnNewConnection(); - void OnReceivePingMessage ( QTime time ); + void OnReceivePingMessage ( int iMs ); signals: void ConClientListMesReceived ( CVector vecChanInfo ); diff --git a/src/protocol.cpp b/src/protocol.cpp index 1d425c59..569cf54e 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -100,9 +100,9 @@ MESSAGES - Ping message (for measuring the ping time) PROTMESSID_PING - +--------------------------------------------------------------------------+ - | 5 bytes transmit time (1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms) | - +--------------------------------------------------------------------------+ + +-----------------------------+ + | 4 bytes transmit time in ms | + +-----------------------------+ ****************************************************************************** @@ -676,40 +676,22 @@ void CProtocol::EvaluateChatTextMes ( unsigned int iPos, const CVector& emit ChatTextReceived ( strChatText ); } -void CProtocol::CreatePingMes ( const QTime time ) +void CProtocol::CreatePingMes ( const int iMs ) { unsigned int iPos = 0; // init position pointer - // build data vector (5 bytes long) - CVector vecData ( 5 ); + // build data vector (4 bytes long) + CVector vecData ( 4 ); - // convert QTime to network time - CVector vNetTimeInfo ( CTimeConv().QTi2NetTi ( time ) ); - - // convert all bytes (byte by byte) - for ( int j = 0; j < 5; j++ ) - { - // byte-by-byte copying of the string data - PutValOnStream ( vecData, iPos, - static_cast ( vNetTimeInfo[j] ), 1 ); - } + // byte-by-byte copying of the string data + PutValOnStream ( vecData, iPos, static_cast ( iMs ), 4 ); CreateAndSendMessage ( PROTMESSID_PING, vecData ); } void CProtocol::EvaluatePingMes ( unsigned int iPos, const CVector& vecData ) { - // time information vector - CVector vNetTimeInfo ( 5 ); // 5 bytes - for ( int j = 0; j < 5; j++ ) - { - // byte-by-byte copying of the time information data - int iData = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); - vNetTimeInfo[j] = static_cast ( iData ); - } - - // convert time to QTime and invoke message action - emit PingReceived ( CTimeConv().NetTi2QTi ( vNetTimeInfo ) ); + emit PingReceived ( static_cast ( GetValFromStream ( vecData, iPos, 4 ) ) ); } diff --git a/src/protocol.h b/src/protocol.h index 51e075df..86e5fefd 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -73,7 +73,7 @@ public: void CreateChanGainMes ( const int iChanID, const double dGain ); void CreateChanNameMes ( const QString strName ); void CreateChatTextMes ( const QString strChatText ); - void CreatePingMes ( const QTime time ); + void CreatePingMes ( const int iMs ); void CreateConClientListMes ( const CVector& vecChanInfo ); @@ -168,7 +168,7 @@ signals: void ChangeChanGain ( int iChanID, double dNewGain ); void ChangeChanName ( QString strName ); void ChatTextReceived ( QString strChatText ); - void PingReceived ( QTime time ); + void PingReceived ( int iMs ); void ConClientListMesReceived ( CVector vecChanInfo ); void ReqJittBufSize(); void ReqConnClientsList(); diff --git a/src/util.h b/src/util.h index 59f22471..80a21a94 100755 --- a/src/util.h +++ b/src/util.h @@ -37,6 +37,8 @@ using namespace std; // because of the library: "vector" #ifdef _WIN32 # include "../windows/moc/aboutdlgbase.h" +# include +# include #else # include "moc/aboutdlgbase.h" #endif @@ -431,39 +433,19 @@ protected: }; -// Time conversion ------------------------------------------------------------- +// Precise time ---------------------------------------------------------------- // needed for ping measurement -class CTimeConv +class CPreciseTime { public: - // QTime to network time vector - static CVector QTi2NetTi ( const QTime qTiIn ) + // precise time (on Windows the QTime is not precise enough) + static int elapsed() { - // vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms - CVector veccNetTi ( 5 ); - - veccNetTi[0] = static_cast ( qTiIn.hour() ); - veccNetTi[1] = static_cast ( qTiIn.minute() ); - veccNetTi[2] = static_cast ( qTiIn.second() ); - - const int iMs = qTiIn.msec(); - veccNetTi[3] = static_cast ( ( iMs >> 8 ) & 255 ); - veccNetTi[4] = static_cast ( iMs & 255 ); - - return veccNetTi; - } - - // network time vector to QTime - static QTime NetTi2QTi ( const CVector netTiIn ) - { - // vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms - return QTime ( - static_cast ( netTiIn[0] ), // hour - static_cast ( netTiIn[1] ), // minute - static_cast ( netTiIn[2] ), // seconds - // msec - static_cast ( ( netTiIn[3] << 8 ) | netTiIn[4] ) - ); +#ifdef _WIN32 + return timeGetTime(); +#else + return QTime().elapsed(); +#endif } };