Merge "OsConstants: Add SOCK_CLOEXEC and SOCK_NONBLOCK"
diff --git a/luni/src/main/java/android/system/OsConstants.java b/luni/src/main/java/android/system/OsConstants.java
index 32c877b..66176bc 100644
--- a/luni/src/main/java/android/system/OsConstants.java
+++ b/luni/src/main/java/android/system/OsConstants.java
@@ -571,7 +571,32 @@
public static final int SIOCGIFBRDADDR = placeholder();
public static final int SIOCGIFDSTADDR = placeholder();
public static final int SIOCGIFNETMASK = placeholder();
+
+ /**
+ * Set the close-on-exec ({@code FD_CLOEXEC}) flag on the new file
+ * descriptor created by {@link Os#socket(int,int,int)} or
+ * {@link Os#socketpair(int,int,int,java.io.FileDescriptor,java.io.FileDescriptor)}.
+ * See the description of the O_CLOEXEC flag in
+ * <a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>
+ * for reasons why this may be useful.
+ *
+ * <p>Applications wishing to make use of this flag on older API versions
+ * may use {@link #O_CLOEXEC} instead. On Android, {@code O_CLOEXEC} and
+ * {@code SOCK_CLOEXEC} are the same value.
+ */
+ public static final int SOCK_CLOEXEC = placeholder();
public static final int SOCK_DGRAM = placeholder();
+
+ /**
+ * Set the O_NONBLOCK file status flag on the file descriptor
+ * created by {@link Os#socket(int,int,int)} or
+ * {@link Os#socketpair(int,int,int,java.io.FileDescriptor,java.io.FileDescriptor)}.
+ *
+ * <p>Applications wishing to make use of this flag on older API versions
+ * may use {@link #O_NONBLOCK} instead. On Android, {@code O_NONBLOCK}
+ * and {@code SOCK_NONBLOCK} are the same value.
+ */
+ public static final int SOCK_NONBLOCK = placeholder();
public static final int SOCK_RAW = placeholder();
public static final int SOCK_SEQPACKET = placeholder();
public static final int SOCK_STREAM = placeholder();
diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp
index 60d36f1..4035921 100644
--- a/luni/src/main/native/android_system_OsConstants.cpp
+++ b/luni/src/main/native/android_system_OsConstants.cpp
@@ -510,7 +510,9 @@
initConstant(env, c, "SIOCGIFBRDADDR", SIOCGIFBRDADDR);
initConstant(env, c, "SIOCGIFDSTADDR", SIOCGIFDSTADDR);
initConstant(env, c, "SIOCGIFNETMASK", SIOCGIFNETMASK);
+ initConstant(env, c, "SOCK_CLOEXEC", SOCK_CLOEXEC);
initConstant(env, c, "SOCK_DGRAM", SOCK_DGRAM);
+ initConstant(env, c, "SOCK_NONBLOCK", SOCK_NONBLOCK);
initConstant(env, c, "SOCK_RAW", SOCK_RAW);
initConstant(env, c, "SOCK_SEQPACKET", SOCK_SEQPACKET);
initConstant(env, c, "SOCK_STREAM", SOCK_STREAM);
diff --git a/luni/src/test/java/libcore/android/system/OsConstantsTest.java b/luni/src/test/java/libcore/android/system/OsConstantsTest.java
index a98707c..a2dc744 100644
--- a/luni/src/test/java/libcore/android/system/OsConstantsTest.java
+++ b/luni/src/test/java/libcore/android/system/OsConstantsTest.java
@@ -35,4 +35,13 @@
public void testTcpUserTimeoutIsDefined() {
assertTrue(OsConstants.TCP_USER_TIMEOUT > 0);
}
+
+ /**
+ * Verifies equality assertions given in the documentation for
+ * {@link OsConstants#SOCK_CLOEXEC} and {@link OsConstants#SOCK_NONBLOCK}.
+ */
+ public void testConstantsEqual() {
+ assertEquals(OsConstants.O_CLOEXEC, OsConstants.SOCK_CLOEXEC);
+ assertEquals(OsConstants.O_NONBLOCK, OsConstants.SOCK_NONBLOCK);
+ }
}