diff options
| author | Neil Fuller <nfuller@google.com> | 2015-07-07 16:11:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-07-07 16:11:48 +0000 |
| commit | 50d11ded0d219ea9b128557080e4ffd49ebea5ab (patch) | |
| tree | 0631c16d255806b4da0d30909c1fa13e26f3c801 /core/java | |
| parent | 0254af6f6831acdf077345bb8c4d7c34d1e6cd34 (diff) | |
| parent | d2df87eb4424ec25ab5c9a8f47cb09a8f191e87f (diff) | |
Merge "Reimplement LocalSocket methods using android.system.Os"
Diffstat (limited to 'core/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; |
