From fc77b947b4fded1c130534859a58b2d7c46a8e96 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Mon, 27 Sep 2021 18:03:51 +0100 Subject: [PATCH 1/2] Improve comparison of IPv4 addresses. --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 5302e9fd03..ffe7ec5edb 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -922,7 +922,7 @@ int CHostAddress::Compare ( const CHostAddress& other ) const quint32 thisAddr = InetAddr.toIPv4Address(); quint32 otherAddr = other.InetAddr.toIPv4Address(); - return (int) thisAddr - (int) otherAddr; + return thisAddr < otherAddr ? -1 : thisAddr > otherAddr ? 1 : 0; } // Instrument picture data base ------------------------------------------------ From 628797495699bc1d998a4c6ea22a0ab3d0ab22da Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Mon, 27 Sep 2021 18:04:24 +0100 Subject: [PATCH 2/2] Improve logging of active channel count Fetch the channel count at the time it changes, and propagate the value to the logging, instead of having the log process fetch the value. This improves the log accuracy when multiple channels connect at the same time. --- src/server.cpp | 4 ++-- src/server.h | 5 +++-- src/socket.cpp | 7 +++++-- src/socket.h | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 504e736994..cdb0defc60 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -562,7 +562,7 @@ void CServer::SendProtMessage ( int iChID, CVector vecMessage ) Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() ); } -void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr ) +void CServer::OnNewConnection ( int iChID, int iTotChans, CHostAddress RecHostAddr ) { QMutexLocker locker ( &Mutex ); @@ -637,7 +637,7 @@ void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr ) DoubleFrameSizeConvBufOut[iChID].Reset(); // logging of new connected channel - Logging.AddNewConnection ( RecHostAddr.InetAddr, GetNumberOfConnectedClients() ); + Logging.AddNewConnection ( RecHostAddr.InetAddr, iTotChans ); } void CServer::OnServerFull ( CHostAddress RecHostAddr ) diff --git a/src/server.h b/src/server.h index 1f10747b00..b33c0fc841 100644 --- a/src/server.h +++ b/src/server.h @@ -181,6 +181,8 @@ class CServer : public QObject, public CServerSlots bool PutAudioData ( const CVector& vecbyRecBuf, const int iNumBytesRead, const CHostAddress& HostAdr, int& iCurChanID ); + int GetNumberOfConnectedClients(); + void GetConCliParam ( CVector& vecHostAddresses, CVector& vecsName, CVector& veciJitBufNumFrames, @@ -261,7 +263,6 @@ class CServer : public QObject, public CServerSlots void InitChannel ( const int iNewChanID, const CHostAddress& InetAddr ); void FreeChannel ( const int iCurChanID ); void DumpChannels ( const QString& title ); - int GetNumberOfConnectedClients(); CVector CreateChannelList(); virtual void CreateAndSendChanListForAllConChannels(); @@ -413,7 +414,7 @@ class CServer : public QObject, public CServerSlots public slots: void OnTimer(); - void OnNewConnection ( int iChID, CHostAddress RecHostAddr ); + void OnNewConnection ( int iChID, int iTotChans, CHostAddress RecHostAddr ); void OnServerFull ( CHostAddress RecHostAddr ); diff --git a/src/socket.cpp b/src/socket.cpp index 3a6622f91a..146ed06782 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -69,7 +69,10 @@ CSocket::CSocket ( CServer* pNServP, const quint16 iPortNumber, const quint16 iQ QObject::connect ( this, &CSocket::ProtcolCLMessageReceived, pServer, &CServer::OnProtcolCLMessageReceived ); - QObject::connect ( this, static_cast ( &CSocket::NewConnection ), pServer, &CServer::OnNewConnection ); + QObject::connect ( this, + static_cast ( &CSocket::NewConnection ), + pServer, + &CServer::OnNewConnection ); QObject::connect ( this, &CSocket::ServerFull, pServer, &CServer::OnServerFull ); } @@ -463,7 +466,7 @@ void CSocket::OnDataReceived() if ( pServer->PutAudioData ( vecbyRecBuf, iNumBytesRead, RecHostAddr, iCurChanID ) ) { // we have a new connection, emit a signal - emit NewConnection ( iCurChanID, RecHostAddr ); + emit NewConnection ( iCurChanID, pServer->GetNumberOfConnectedClients(), RecHostAddr ); // this was an audio packet, start server if it is in sleep mode if ( !pServer->IsRunning() ) diff --git a/src/socket.h b/src/socket.h index c29df14d9d..fee83488ce 100644 --- a/src/socket.h +++ b/src/socket.h @@ -97,7 +97,7 @@ class CSocket : public QObject signals: void NewConnection(); // for the client - void NewConnection ( int iChID, + void NewConnection ( int iChID, int iTotChans, CHostAddress RecHostAddr ); // for the server void ServerFull ( CHostAddress RecHostAddr );