Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5822d7e4 authored by Christine Hallstrom's avatar Christine Hallstrom Committed by Andre Eisenbach
Browse files

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
parent d1c5127c
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -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;
                        tmpOffset += tmpLength;
                        bytesToWrite -= tmpLength;
                    }
                    } while(!done);

                }
            } else {
                mSocketOS.write(b, offset, length);