--- a/src/java.base/share/classes/sun/nio/ch/Net.java Fri Mar 22 13:42:45 2019 +0530
+++ b/src/java.base/share/classes/sun/nio/ch/Net.java Fri Mar 22 11:35:35 2019 +0000
@@ -310,6 +310,12 @@
static final ExtendedSocketOptions extendedOptions =
ExtendedSocketOptions.getInstance();
+ static void setSocketOption(FileDescriptor fd, SocketOption<?> name, Object value)
+ throws IOException
+ {
+ setSocketOption(fd, Net.UNSPEC, name, value);
+ }
+
static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
SocketOption<?> name, Object value)
throws IOException
@@ -372,8 +378,13 @@
setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6);
}
- static Object getSocketOption(FileDescriptor fd, ProtocolFamily family,
- SocketOption<?> name)
+ static Object getSocketOption(FileDescriptor fd, SocketOption<?> name)
+ throws IOException
+ {
+ return getSocketOption(fd, Net.UNSPEC, name);
+ }
+
+ static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, SocketOption<?> name)
throws IOException
{
Class<?> type = name.type();
@@ -426,8 +437,7 @@
return socket(UNSPEC, stream);
}
- static FileDescriptor socket(ProtocolFamily family, boolean stream)
- throws IOException {
+ static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException {
boolean preferIPv6 = isIPv6Available() &&
(family != StandardProtocolFamily.INET);
return IOUtil.newFD(socket0(preferIPv6, stream, false, fastLoopback));
@@ -525,21 +535,44 @@
int level, int opt, int arg, boolean isIPv6)
throws IOException;
+ /**
+ * Polls a file descriptor for events.
+ * @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely
+ * @return the polled events or 0 if no events are polled
+ */
static native int poll(FileDescriptor fd, int events, long timeout)
throws IOException;
/**
+ * Performs a non-blocking poll of a file descriptor.
+ * @return the polled events or 0 if no events are polled
+ */
+ static int pollNow(FileDescriptor fd, int events) throws IOException {
+ return poll(fd, events, 0);
+ }
+
+ /**
* Polls a connecting socket to test if the connection has been established.
*
* @apiNote This method is public to allow it be used by code in jdk.sctp.
*
* @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely
- * @return 1 if connected, 0 if not connected, or IOS_INTERRUPTED
+ * @return true if connected
*/
- public static native int pollConnect(FileDescriptor fd, long timeout)
+ public static native boolean pollConnect(FileDescriptor fd, long timeout)
throws IOException;
/**
+ * Performs a non-blocking poll of a connecting socket to test if the
+ * connection has been established.
+ *
+ * @return true if connected
+ */
+ static boolean pollConnectNow(FileDescriptor fd) throws IOException {
+ return pollConnect(fd, 0);
+ }
+
+ /**
* Return the number of bytes in the socket input buffer.
*/
static native int available(FileDescriptor fd) throws IOException;