From 4b83fa6fe0686ae73195a85733d5efb900946352 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 23 Jan 2014 20:33:55 +0000 Subject: [PATCH] avoid allocating memory in time critical routines --- src/socket.cpp | 7 +++---- src/socket.h | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index f2b167ee..2ffe451c 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -43,6 +43,7 @@ void CSocket::Init ( const quint16 iPortNumber ) // incremented port numbers quint16 iClientPortIncrement = 10; // start value: port nubmer plus ten bSuccess = false; // initialization for while loop + while ( !bSuccess && ( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) ) { @@ -136,9 +137,6 @@ void CSocket::OnDataReceived() { while ( SocketDevice.hasPendingDatagrams() ) { - QHostAddress SenderAddress; - quint16 SenderPort; - // read block from network interface and query address of sender const int iNumBytesRead = SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0], @@ -153,7 +151,8 @@ void CSocket::OnDataReceived() } // convert address of client - const CHostAddress RecHostAddr ( SenderAddress, SenderPort ); + RecHostAddr.InetAddr = SenderAddress; + RecHostAddr.iPort = SenderPort; if ( bIsClient ) { diff --git a/src/socket.h b/src/socket.h index b45a5103..9cf58632 100755 --- a/src/socket.h +++ b/src/socket.h @@ -80,6 +80,8 @@ protected: CVector vecbyRecBuf; CHostAddress RecHostAddr; + QHostAddress SenderAddress; + quint16 SenderPort; CChannel* pChannel; // for client CServer* pServer; // for server