diff options
| author | 2016-06-17 16:00:25 -0700 | |
|---|---|---|
| committer | 2016-06-18 00:09:45 +0000 | |
| commit | fc59c344bfd792674d9bfa388c4afe8bc00a90a4 (patch) | |
| tree | f03d1cca4dd60d4705509359f4d17be6f73a1890 | |
| parent | 01e7c10d375d98e255c4adaac4d310ffb3f0b8d2 (diff) | |
Fix early termination of while loop in BluetoothSocket#write
While loop exits too early and misses writing remaining bytes.
Also restructured the loop itself to be more readable.
Change-Id: I71e9b331d20b5ae70175450c3346be43ab56c40c
| -rw-r--r-- | core/java/android/bluetooth/BluetoothSocket.java | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java index ae12c88ff233..ec01beff9310 100644 --- a/core/java/android/bluetooth/BluetoothSocket.java +++ b/core/java/android/bluetooth/BluetoothSocket.java @@ -532,22 +532,19 @@ public final class BluetoothSocket implements Closeable { if(length <= mMaxTxPacketSize) { mSocketOS.write(b, offset, length); } else { - int tmpOffset = offset; - int tmpLength = mMaxTxPacketSize; - int endIndex = offset + length; - boolean done = false; if(DBG) Log.w(TAG, "WARNING: Write buffer larger than L2CAP packet size!\n" + "Packet will be divided into SDU packets of size " + mMaxTxPacketSize); - do{ + int tmpOffset = offset; + int bytesToWrite = length; + while (bytesToWrite > 0) { + int tmpLength = (bytesToWrite > mMaxTxPacketSize) + ? mMaxTxPacketSize + : bytesToWrite; mSocketOS.write(b, tmpOffset, tmpLength); - tmpOffset += mMaxTxPacketSize; - if((tmpOffset + mMaxTxPacketSize) > endIndex) { - tmpLength = endIndex - tmpOffset; - done = true; - } - } while(!done); - + tmpOffset += tmpLength; + bytesToWrite -= tmpLength; + } } } else { mSocketOS.write(b, offset, length); |