diff options
| author | Neil Fuller <nfuller@google.com> | 2015-07-03 15:06:23 +0100 |
|---|---|---|
| committer | Neil Fuller <nfuller@google.com> | 2015-07-03 15:16:37 +0100 |
| commit | d2df87eb4424ec25ab5c9a8f47cb09a8f191e87f (patch) | |
| tree | 7c9ed20ae56ccf3d99534109741dff4d71e88b93 /core/java/android/net/LocalSocketImpl.java | |
| parent | c80af6d84d8fb729f17028ac533fac07bb7c4c5d (diff) | |
Reimplement LocalSocket methods using android.system.Os
InputStream.available()
OutputStream.flush()
Bug: 3106438
Change-Id: I3a9425c323229e27bb72f6232dd13f7579586840
Diffstat (limited to 'core/java/android/net/LocalSocketImpl.java')
| -rw-r--r-- | core/java/android/net/LocalSocketImpl.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/core/java/android/net/LocalSocketImpl.java b/core/java/android/net/LocalSocketImpl.java index 8823ab14aa80..d26e22db3923 100644 --- a/core/java/android/net/LocalSocketImpl.java +++ b/core/java/android/net/LocalSocketImpl.java @@ -27,6 +27,7 @@ import android.system.Os; import android.system.OsConstants; import android.system.StructLinger; import android.system.StructTimeval; +import android.util.MutableInt; /** * Socket implementation used for android.net.LocalSocket and @@ -61,7 +62,13 @@ class LocalSocketImpl FileDescriptor myFd = fd; if (myFd == null) throw new IOException("socket closed"); - return available_native(myFd); + MutableInt avail = new MutableInt(0); + try { + Os.ioctlInt(myFd, OsConstants.FIONREAD, avail); + } catch (ErrnoException e) { + throw e.rethrowAsIOException(); + } + return avail.value; } /** {@inheritDoc} */ @@ -158,18 +165,31 @@ class LocalSocketImpl public void flush() throws IOException { FileDescriptor myFd = fd; if (myFd == null) throw new IOException("socket closed"); - while(pending_native(myFd) > 0) { + + // Loop until the output buffer is empty. + MutableInt pending = new MutableInt(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) { - return; + break; } } } } - private native int pending_native(FileDescriptor fd) throws IOException; - private native int available_native(FileDescriptor fd) throws IOException; private native int read_native(FileDescriptor fd) throws IOException; private native int readba_native(byte[] b, int off, int len, FileDescriptor fd) throws IOException; |
