fix for ping measurement under Windows
This commit is contained in:
parent
c717fc11a9
commit
4d980a8a54
7 changed files with 45 additions and 81 deletions
|
@ -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<CChannelShortInfo> 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 )
|
||||
|
|
|
@ -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<uint8_t> vecMessage );
|
||||
|
|
|
@ -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<uint8_t> 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 )
|
||||
|
|
|
@ -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<CChannelShortInfo> vecChanInfo );
|
||||
|
|
|
@ -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<uint8_t>&
|
|||
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<uint8_t> vecData ( 5 );
|
||||
// build data vector (4 bytes long)
|
||||
CVector<uint8_t> vecData ( 4 );
|
||||
|
||||
// convert QTime to network time
|
||||
CVector<unsigned char> 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<uint32_t> ( vNetTimeInfo[j] ), 1 );
|
||||
}
|
||||
// byte-by-byte copying of the string data
|
||||
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
|
||||
|
||||
CreateAndSendMessage ( PROTMESSID_PING, vecData );
|
||||
}
|
||||
|
||||
void CProtocol::EvaluatePingMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
||||
{
|
||||
// time information vector
|
||||
CVector<unsigned char> vNetTimeInfo ( 5 ); // 5 bytes
|
||||
for ( int j = 0; j < 5; j++ )
|
||||
{
|
||||
// byte-by-byte copying of the time information data
|
||||
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||
vNetTimeInfo[j] = static_cast<unsigned char> ( iData );
|
||||
}
|
||||
|
||||
// convert time to QTime and invoke message action
|
||||
emit PingReceived ( CTimeConv().NetTi2QTi ( vNetTimeInfo ) );
|
||||
emit PingReceived ( static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<CChannelShortInfo>& 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<CChannelShortInfo> vecChanInfo );
|
||||
void ReqJittBufSize();
|
||||
void ReqConnClientsList();
|
||||
|
|
40
src/util.h
40
src/util.h
|
@ -37,6 +37,8 @@
|
|||
using namespace std; // because of the library: "vector"
|
||||
#ifdef _WIN32
|
||||
# include "../windows/moc/aboutdlgbase.h"
|
||||
# include <windows.h>
|
||||
# include <mmsystem.h>
|
||||
#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<unsigned char> 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<unsigned char> veccNetTi ( 5 );
|
||||
|
||||
veccNetTi[0] = static_cast<unsigned char> ( qTiIn.hour() );
|
||||
veccNetTi[1] = static_cast<unsigned char> ( qTiIn.minute() );
|
||||
veccNetTi[2] = static_cast<unsigned char> ( qTiIn.second() );
|
||||
|
||||
const int iMs = qTiIn.msec();
|
||||
veccNetTi[3] = static_cast<unsigned char> ( ( iMs >> 8 ) & 255 );
|
||||
veccNetTi[4] = static_cast<unsigned char> ( iMs & 255 );
|
||||
|
||||
return veccNetTi;
|
||||
}
|
||||
|
||||
// network time vector to QTime
|
||||
static QTime NetTi2QTi ( const CVector<unsigned char> netTiIn )
|
||||
{
|
||||
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
|
||||
return QTime (
|
||||
static_cast<int> ( netTiIn[0] ), // hour
|
||||
static_cast<int> ( netTiIn[1] ), // minute
|
||||
static_cast<int> ( netTiIn[2] ), // seconds
|
||||
// msec
|
||||
static_cast<int> ( ( netTiIn[3] << 8 ) | netTiIn[4] )
|
||||
);
|
||||
#ifdef _WIN32
|
||||
return timeGetTime();
|
||||
#else
|
||||
return QTime().elapsed();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue