diff options
author | Elliott Hughes <enh@google.com> | 2014-12-12 22:00:46 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-12-12 22:00:47 +0000 |
commit | d355c4a9ff58b8a8f57209f2232ed2f170a7828c (patch) | |
tree | 045bf28685f704b11b95c0a4838360b510fd0a90 | |
parent | b6609f097c773b74ba070fab5b88b7d79c89d29f (diff) | |
parent | 0d8b5c3692c36837d22c4e7d9c4d7d95f6a10235 (diff) | |
download | libcore-d355c4a9ff58b8a8f57209f2232ed2f170a7828c.zip libcore-d355c4a9ff58b8a8f57209f2232ed2f170a7828c.tar.gz libcore-d355c4a9ff58b8a8f57209f2232ed2f170a7828c.tar.bz2 |
Merge "Add pipe2 and O_CLOEXEC to the libcore POSIX API."
-rw-r--r-- | luni/src/main/java/android/system/Os.java | 4 | ||||
-rw-r--r-- | luni/src/main/java/android/system/OsConstants.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/java/nio/SelectorImpl.java | 2 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/ForwardingOs.java | 2 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/Os.java | 2 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/Posix.java | 2 | ||||
-rw-r--r-- | luni/src/main/native/android_system_OsConstants.cpp | 1 | ||||
-rw-r--r-- | luni/src/main/native/libcore_io_Posix.cpp | 6 | ||||
-rw-r--r-- | luni/src/test/java/libcore/java/io/FileInputStreamTest.java | 2 |
9 files changed, 13 insertions, 9 deletions
diff --git a/luni/src/main/java/android/system/Os.java b/luni/src/main/java/android/system/Os.java index 9d6dc1b..7f73a85 100644 --- a/luni/src/main/java/android/system/Os.java +++ b/luni/src/main/java/android/system/Os.java @@ -302,7 +302,9 @@ public final class Os { /** * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>. */ - public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe(); } + public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); } + + /** @hide */ public static FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); } /** * See <a href="http://man7.org/linux/man-pages/man2/poll.2.html">poll(2)</a>. diff --git a/luni/src/main/java/android/system/OsConstants.java b/luni/src/main/java/android/system/OsConstants.java index c758eb7..55870ec 100644 --- a/luni/src/main/java/android/system/OsConstants.java +++ b/luni/src/main/java/android/system/OsConstants.java @@ -331,6 +331,7 @@ public final class OsConstants { public static final int NI_NUMERICSERV = placeholder(); public static final int O_ACCMODE = placeholder(); public static final int O_APPEND = placeholder(); + /** @hide */ public static final int O_CLOEXEC = placeholder(); public static final int O_CREAT = placeholder(); public static final int O_EXCL = placeholder(); public static final int O_NOCTTY = placeholder(); diff --git a/luni/src/main/java/java/nio/SelectorImpl.java b/luni/src/main/java/java/nio/SelectorImpl.java index 45406b1..5e2a2b1 100644 --- a/luni/src/main/java/java/nio/SelectorImpl.java +++ b/luni/src/main/java/java/nio/SelectorImpl.java @@ -94,7 +94,7 @@ final class SelectorImpl extends AbstractSelector { * configure the pipe so we can fully drain it without blocking. */ try { - FileDescriptor[] pipeFds = Libcore.os.pipe(); + FileDescriptor[] pipeFds = Libcore.os.pipe2(0); wakeupIn = pipeFds[0]; wakeupOut = pipeFds[1]; IoUtils.setBlocking(wakeupIn, false); diff --git a/luni/src/main/java/libcore/io/ForwardingOs.java b/luni/src/main/java/libcore/io/ForwardingOs.java index 584fd58..9fd4322 100644 --- a/luni/src/main/java/libcore/io/ForwardingOs.java +++ b/luni/src/main/java/libcore/io/ForwardingOs.java @@ -113,7 +113,7 @@ public class ForwardingOs implements Os { public void munlock(long address, long byteCount) throws ErrnoException { os.munlock(address, byteCount); } public void munmap(long address, long byteCount) throws ErrnoException { os.munmap(address, byteCount); } public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return os.open(path, flags, mode); } - public FileDescriptor[] pipe() throws ErrnoException { return os.pipe(); } + public FileDescriptor[] pipe2(int flags) throws ErrnoException { return os.pipe2(flags); } public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); } public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { os.posix_fallocate(fd, offset, length); } public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return os.prctl(option, arg2, arg3, arg4, arg5); }; diff --git a/luni/src/main/java/libcore/io/Os.java b/luni/src/main/java/libcore/io/Os.java index 9f080a6..ad0767e 100644 --- a/luni/src/main/java/libcore/io/Os.java +++ b/luni/src/main/java/libcore/io/Os.java @@ -105,7 +105,7 @@ public interface Os { public void munlock(long address, long byteCount) throws ErrnoException; public void munmap(long address, long byteCount) throws ErrnoException; public FileDescriptor open(String path, int flags, int mode) throws ErrnoException; - public FileDescriptor[] pipe() throws ErrnoException; + public FileDescriptor[] pipe2(int flags) throws ErrnoException; /* TODO: if we used the non-standard ppoll(2) behind the scenes, we could take a long timeout. */ public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException; diff --git a/luni/src/main/java/libcore/io/Posix.java b/luni/src/main/java/libcore/io/Posix.java index cab67e8..73b0dc4 100644 --- a/luni/src/main/java/libcore/io/Posix.java +++ b/luni/src/main/java/libcore/io/Posix.java @@ -107,7 +107,7 @@ public final class Posix implements Os { public native void munlock(long address, long byteCount) throws ErrnoException; public native void munmap(long address, long byteCount) throws ErrnoException; public native FileDescriptor open(String path, int flags, int mode) throws ErrnoException; - public native FileDescriptor[] pipe() throws ErrnoException; + public native FileDescriptor[] pipe2(int flags) throws ErrnoException; public native int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; public native void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException; public native int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException; diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp index 92212b9..f00c922 100644 --- a/luni/src/main/native/android_system_OsConstants.cpp +++ b/luni/src/main/native/android_system_OsConstants.cpp @@ -362,6 +362,7 @@ static void OsConstants_initConstants(JNIEnv* env, jclass c) { initConstant(env, c, "NI_NUMERICSERV", NI_NUMERICSERV); initConstant(env, c, "O_ACCMODE", O_ACCMODE); initConstant(env, c, "O_APPEND", O_APPEND); + initConstant(env, c, "O_CLOEXEC", O_CLOEXEC); initConstant(env, c, "O_CREAT", O_CREAT); initConstant(env, c, "O_EXCL", O_EXCL); initConstant(env, c, "O_NOCTTY", O_NOCTTY); diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp index ce29226..1be14b4 100644 --- a/luni/src/main/native/libcore_io_Posix.cpp +++ b/luni/src/main/native/libcore_io_Posix.cpp @@ -1035,9 +1035,9 @@ static jobject Posix_open(JNIEnv* env, jobject, jstring javaPath, jint flags, ji return fd != -1 ? jniCreateFileDescriptor(env, fd) : NULL; } -static jobjectArray Posix_pipe(JNIEnv* env, jobject) { +static jobjectArray Posix_pipe2(JNIEnv* env, jobject, jint flags) { int fds[2]; - throwIfMinusOne(env, "pipe", TEMP_FAILURE_RETRY(pipe(&fds[0]))); + throwIfMinusOne(env, "pipe2", TEMP_FAILURE_RETRY(pipe2(&fds[0], flags))); jobjectArray result = env->NewObjectArray(2, JniConstants::fileDescriptorClass, NULL); if (result == NULL) { return NULL; @@ -1594,7 +1594,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(Posix, munlock, "(JJ)V"), NATIVE_METHOD(Posix, munmap, "(JJ)V"), NATIVE_METHOD(Posix, open, "(Ljava/lang/String;II)Ljava/io/FileDescriptor;"), - NATIVE_METHOD(Posix, pipe, "()[Ljava/io/FileDescriptor;"), + NATIVE_METHOD(Posix, pipe2, "()[Ljava/io/FileDescriptor;"), NATIVE_METHOD(Posix, poll, "([Landroid/system/StructPollfd;I)I"), NATIVE_METHOD(Posix, posix_fallocate, "(Ljava/io/FileDescriptor;JJ)V"), NATIVE_METHOD(Posix, prctl, "(IJJJJ)I"), diff --git a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java index 14950ee..26de11a 100644 --- a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java +++ b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java @@ -67,7 +67,7 @@ public final class FileInputStreamTest extends TestCase { } public void testSkipInPipes() throws Exception { - FileDescriptor[] pipe = Libcore.os.pipe(); + FileDescriptor[] pipe = Libcore.os.pipe2(0); DataFeeder feeder = new DataFeeder(pipe[1]); try { feeder.start(); |