From dc47b46719405b3fb49a748c8452e8984ceb0d66 Mon Sep 17 00:00:00 2001 From: Juffin Alex Varghese Date: Fri, 30 Jan 2015 18:57:11 +0530 Subject: Bluetooth-OPP: Check socket congestion status before writing the data This change will ensure that data will be send to socket only after congestion is cleared. Otherwise, if socket is already in congestion and send the data before clearing, will cause transfer failure. CRs-Fixed: 790313 Change-Id: I8847a9f3473d97cd6fadf24e293ac179418df457 --- .../bluetooth/opp/BluetoothOppObexClientSession.java | 14 ++++++++++++++ src/com/android/bluetooth/opp/BluetoothOppTransport.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 6684b1fd7..0b480e70b 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -587,6 +587,20 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } readLength = a.read(buffer, 0, outputBufferSize); + + while (true) { + int congStatus = ((BluetoothOppTransport)mTransport1).getSockCongStatus(); + if ((congStatus == 0) || (congStatus == -1)) { + break; + } + try { + Thread.sleep(5); + } catch (InterruptedException slpe) { + Log.v(TAG, "Interrupted while checking the socket congestion evt"); + break; + } + } + int writtenLength = 0; while (writtenLength != readLength) { //SET MTU SIZE BEFORE WRITE diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransport.java b/src/com/android/bluetooth/opp/BluetoothOppTransport.java index 25c66fc7e..0615c1899 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppTransport.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransport.java @@ -99,6 +99,21 @@ public class BluetoothOppTransport implements ObexTransport { return status; } + /** + * Returns the Congestion status of the Socket + */ + public int getSockCongStatus() { + ByteBuffer bb = ByteBuffer.allocate(4); + bb.order(ByteOrder.LITTLE_ENDIAN); + int status; + try { + status = mSocket.getSocketOpt(5, bb.array()); + } catch (IOException ex) { + return -1; + } + return bb.getInt(); + } + public void connect() throws IOException { } -- cgit v1.2.3