diff options
| author | Android Build Merger (Role) <noreply-android-build-merger@google.com> | 2019-09-03 22:03:42 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-09-03 22:03:42 +0000 |
| commit | 6399a34a4dd0b9202c22eddebce382ab1cc16a41 (patch) | |
| tree | 284aaa1ed66990f78f0c62661d6d5ec48652bede /core/java | |
| parent | 31856440555036492591570ac050beed24de9bb9 (diff) | |
| parent | f1ed8566b652fb1210d1d12ab83893301cd194d2 (diff) | |
Merge "Merge "Revert "Remove a misleading "flush" function."" am: 9fcf8b7cae am: 783313acbf am: 013c618a41 am: b2a36aefa9" into qt-qpr1-dev-plus-aosp
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothOutputStream.java | 12 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothSocket.java | 14 | ||||
| -rw-r--r-- | core/java/android/net/LocalSocketImpl.java | 34 |
3 files changed, 60 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothOutputStream.java b/core/java/android/bluetooth/BluetoothOutputStream.java index a0aa2dee9d34..dfec4e102fd4 100644 --- a/core/java/android/bluetooth/BluetoothOutputStream.java +++ b/core/java/android/bluetooth/BluetoothOutputStream.java @@ -75,4 +75,16 @@ import java.io.OutputStream; } mSocket.write(b, offset, count); } + + /** + * Wait until the data in sending queue is emptied. A polling version + * for flush implementation. Use it to ensure the writing data afterwards will + * be packed in the new RFCOMM frame. + * + * @throws IOException if an i/o error occurs. + * @since Android 4.2.3 + */ + public void flush() throws IOException { + mSocket.flush(); + } } diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java index 760166bfcc5d..a6e3153d6af7 100644 --- a/core/java/android/bluetooth/BluetoothSocket.java +++ b/core/java/android/bluetooth/BluetoothSocket.java @@ -515,6 +515,20 @@ public final class BluetoothSocket implements Closeable { return mSocketIS.available(); } + /** + * Wait until the data in sending queue is emptied. A polling version + * for flush implementation. Used to ensure the writing data afterwards will + * be packed in new RFCOMM frame. + * + * @throws IOException if an i/o error occurs. + */ + @UnsupportedAppUsage + /*package*/ void flush() throws IOException { + if (mSocketOS == null) throw new IOException("flush is called on null OutputStream"); + if (VDBG) Log.d(TAG, "flush: " + mSocketOS); + mSocketOS.flush(); + } + /*package*/ int read(byte[] b, int offset, int length) throws IOException { int ret = 0; if (VDBG) Log.d(TAG, "read in: " + mSocketIS + " len: " + length); diff --git a/core/java/android/net/LocalSocketImpl.java b/core/java/android/net/LocalSocketImpl.java index b066a15106af..fe7632c25445 100644 --- a/core/java/android/net/LocalSocketImpl.java +++ b/core/java/android/net/LocalSocketImpl.java @@ -157,6 +157,40 @@ class LocalSocketImpl write_native(b, myFd); } } + + /** + * Wait until the data in sending queue is emptied. A polling version + * for flush implementation. + * @throws IOException + * if an i/o error occurs. + */ + @Override + public void flush() throws IOException { + FileDescriptor myFd = fd; + if (myFd == null) throw new IOException("socket closed"); + + // Loop until the output buffer is empty. + Int32Ref pending = new Int32Ref(0); + while (true) { + try { + // See linux/net/unix/af_unix.c + Os.ioctlInt(myFd, OsConstants.TIOCOUTQ, pending); + } catch (ErrnoException e) { + throw e.rethrowAsIOException(); + } + + if (pending.value <= 0) { + // The output buffer is empty. + break; + } + + try { + Thread.sleep(10); + } catch (InterruptedException ie) { + break; + } + } + } } private native int read_native(FileDescriptor fd) throws IOException; |
