diff --git a/src/channel.cpp b/src/channel.cpp index 68f42d53..d4015d8c 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -184,7 +184,9 @@ void CChannelSet::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, ChanName = addrTest.toString(); } - // add name of the client at the beginning of the message text + // add name of the client at the beginning of the message text and use + // different colors, to get correct HTML, the "<" and ">" signs must be + // replaced by "<" and ">" QString sCurColor = vstrChatColors[iCurChanID % vstrChatColors.Size()]; const QString strActualMessageText = "<" + ChanName + @@ -213,7 +215,7 @@ int CChannelSet::GetFreeChan() } } - /* no free channel found, return invalid ID */ + // no free channel found, return invalid ID return INVALID_CHANNEL_ID; } @@ -221,12 +223,12 @@ int CChannelSet::CheckAddr ( const CHostAddress& Addr ) { CHostAddress InetAddr; - /* Check for all possible channels if IP is already in use */ + // check for all possible channels if IP is already in use for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) { if ( vecChannels[i].GetAddress ( InetAddr ) ) { - /* IP found, return channel number */ + // IP found, return channel number if ( InetAddr == Addr ) { return i; @@ -234,7 +236,7 @@ int CChannelSet::CheckAddr ( const CHostAddress& Addr ) } } - /* IP not found, return invalid ID */ + // IP not found, return invalid ID return INVALID_CHANNEL_ID; } @@ -249,7 +251,7 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, { bool bChanOK = true; - // get channel ID ------------------------------------------------------ + // Get channel ID ------------------------------------------------------ // check address int iCurChanID = CheckAddr ( HostAdr ); @@ -294,7 +296,7 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, } - // put received data in jitter buffer ---------------------------------- + // Put received data in jitter buffer ---------------------------------- if ( bChanOK ) { // put packet in socket buffer diff --git a/src/channel.h b/src/channel.h index a1f0ccb0..3e781df4 100755 --- a/src/channel.h +++ b/src/channel.h @@ -273,12 +273,12 @@ public slots: // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! // send message - void OnSendProtMessCh0 ( CVector mess ) {emit MessReadyForSending ( 0, mess ); } - void OnSendProtMessCh1 ( CVector mess ) {emit MessReadyForSending ( 1, mess ); } - void OnSendProtMessCh2 ( CVector mess ) {emit MessReadyForSending ( 2, mess ); } - void OnSendProtMessCh3 ( CVector mess ) {emit MessReadyForSending ( 3, mess ); } - void OnSendProtMessCh4 ( CVector mess ) {emit MessReadyForSending ( 4, mess ); } - void OnSendProtMessCh5 ( CVector mess ) {emit MessReadyForSending ( 5, mess ); } + void OnSendProtMessCh0 ( CVector mess ) { emit MessReadyForSending ( 0, mess ); } + void OnSendProtMessCh1 ( CVector mess ) { emit MessReadyForSending ( 1, mess ); } + void OnSendProtMessCh2 ( CVector mess ) { emit MessReadyForSending ( 2, mess ); } + void OnSendProtMessCh3 ( CVector mess ) { emit MessReadyForSending ( 3, mess ); } + void OnSendProtMessCh4 ( CVector mess ) { emit MessReadyForSending ( 4, mess ); } + void OnSendProtMessCh5 ( CVector mess ) { emit MessReadyForSending ( 5, mess ); } void OnNewConnectionCh0() { vecChannels[0].CreateReqJitBufMes(); } void OnNewConnectionCh1() { vecChannels[1].CreateReqJitBufMes(); } diff --git a/src/protocol.cpp b/src/protocol.cpp index cfd42168..fa0c83cd 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -146,14 +146,10 @@ void CProtocol::EnqueueMessage ( CVector& vecMessage, { // check if list is empty so that we have to initiate a send process bListWasEmpty = SendMessQueue.empty(); - } - Mutex.unlock(); - // create send message object for the queue - CSendMessage SendMessageObj ( vecMessage, iCnt, iID ); + // create send message object for the queue + CSendMessage SendMessageObj ( vecMessage, iCnt, iID ); - Mutex.lock(); - { // we want to have a FIFO: we add at the end and take from the beginning SendMessQueue.push_back ( SendMessageObj ); } @@ -168,22 +164,20 @@ void CProtocol::EnqueueMessage ( CVector& vecMessage, void CProtocol::SendMessage() { - CVector vecMessage; - bool bSendMess = false; + QMutexLocker locker ( &Mutex ); - Mutex.lock(); + CVector vecMessage; + bool bSendMess = false; + + // we have to check that list is not empty, since in another thread the + // last element of the list might have been erased + if ( !SendMessQueue.empty() ) { - // we have to check that list is not empty, since in another thread the - // last element of the list might have been erased - if ( !SendMessQueue.empty() ) - { - vecMessage.Init ( SendMessQueue.front().vecMessage.Size() ); - vecMessage = SendMessQueue.front().vecMessage; + vecMessage.Init ( SendMessQueue.front().vecMessage.Size() ); + vecMessage = SendMessQueue.front().vecMessage; - bSendMess = true; - } + bSendMess = true; } - Mutex.unlock(); if ( bSendMess ) { @@ -206,8 +200,8 @@ void CProtocol::SendMessage() void CProtocol::CreateAndSendMessage ( const int iID, const CVector& vecData ) { - CVector vecNewMessage; - int iCurCounter; + CVector vecNewMessage; + int iCurCounter; Mutex.lock(); { @@ -228,9 +222,9 @@ void CProtocol::CreateAndSendMessage ( const int iID, void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt ) { - CVector vecAcknMessage; - CVector vecData ( 2 ); // 2 bytes of data - unsigned int iPos = 0; // init position pointer + CVector vecAcknMessage; + CVector vecData ( 2 ); // 2 bytes of data + unsigned int iPos = 0; // init position pointer // build data vector PutValOnStream ( vecData, iPos, static_cast ( iID ), 2 ); @@ -244,12 +238,10 @@ void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt ) void CProtocol::DeleteSendMessQueue() { - Mutex.lock(); - { - // delete complete "send message queue" - SendMessQueue.clear(); - } - Mutex.unlock(); + QMutexLocker locker ( &Mutex ); + + // delete complete "send message queue" + SendMessQueue.clear(); } bool CProtocol::ParseMessage ( const CVector& vecbyData, @@ -283,7 +275,7 @@ for ( int i = 0; i < iNumBytes; i++ ) { // acknowledgments are not acknowledged if ( iRecID != PROTMESSID_ACKN ) { - // re-send acknowledgement + // resend acknowledgement CreateAndSendAcknMess ( iRecID, iRecCounter ); } } @@ -382,7 +374,7 @@ for ( int i = 0; i < iNumBytes; i++ ) { } } - // save current message ID and counter to find out if message was re-sent + // save current message ID and counter to find out if message was resent iOldRecID = iRecID; iOldRecCnt = iRecCounter; }