diff options
author | Evan Chu <evanchu@broadcom.com> | 2012-09-05 11:30:46 -0400 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2012-09-06 12:20:37 +0200 |
commit | 7e5bdc93fb55d2090c4b32bff811abf4c39b2e52 (patch) | |
tree | 82a6bd3bae81ee0aed81593f310084cf028da2a3 | |
parent | 08030f1c2a13eca1acc67b9d0763a3b6a2706f02 (diff) | |
download | packages_apps_nfc-7e5bdc93fb55d2090c4b32bff811abf4c39b2e52.zip packages_apps_nfc-7e5bdc93fb55d2090c4b32bff811abf4c39b2e52.tar.gz packages_apps_nfc-7e5bdc93fb55d2090c4b32bff811abf4c39b2e52.tar.bz2 |
correctly handle P2P congestion event
Correctly handle NFA_P2P_CONGEST_EVT to prevent race condition.
Change-Id: If255ade96867d45b2a7cff1cb3d6e4cbc2d883d3
-rw-r--r-- | nci/jni/PeerToPeer.cpp | 25 |
1 files 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; |