From 7e5bdc93fb55d2090c4b32bff811abf4c39b2e52 Mon Sep 17 00:00:00 2001 From: Evan Chu Date: Wed, 5 Sep 2012 11:30:46 -0400 Subject: correctly handle P2P congestion event Correctly handle NFA_P2P_CONGEST_EVT to prevent race condition. Change-Id: If255ade96867d45b2a7cff1cb3d6e4cbc2d883d3 --- nci/jni/PeerToPeer.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/nci/jni/PeerToPeer.cpp b/nci/jni/PeerToPeer.cpp index 02aded1..fdfa30c 100644 --- a/nci/jni/PeerToPeer.cpp +++ b/nci/jni/PeerToPeer.cpp @@ -1033,17 +1033,20 @@ bool PeerToPeer::send (tJNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferLen) return (sendViaSnep(jniHandle, buffer, bufferLen)); } - nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); - - while (nfaStat == NFA_STATUS_CONGESTED) + while (true) { SyncEventGuard guard (pConn->mCongEvent); - pConn->mCongEvent.wait (); + nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); + if (nfaStat == NFA_STATUS_CONGESTED) + pConn->mCongEvent.wait (); //wait for NFA_P2P_CONGEST_EVT + else + break; - if (pConn->mNfaConnHandle == NFA_HANDLE_INVALID) + if (pConn->mNfaConnHandle == NFA_HANDLE_INVALID) //peer already disconnected + { + ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: peer disconnected", fn); return (false); - - nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); + } } if (nfaStat == NFA_STATUS_OK) @@ -1629,9 +1632,11 @@ void PeerToPeer::nfaServerCallback (tNFA_P2P_EVT p2pEvent, tNFA_P2P_EVT_DATA* ev { ALOGD ("%s: NFA_P2P_CONGEST_EVT; nfa handle: 0x%04x congested: %u", fn, eventData->congest.handle, eventData->congest.is_congested); - - SyncEventGuard guard (pConn->mCongEvent); - pConn->mCongEvent.notifyOne(); + if (eventData->congest.is_congested == FALSE) + { + SyncEventGuard guard (pConn->mCongEvent); + pConn->mCongEvent.notifyOne(); + } } break; -- cgit v1.1