< prev index next >
src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c
Print this page
rev 12681 : [mq]: 8072466-Deadlock-when-starting-MulticastSocket-and-DatagramSocket
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -68,18 +68,28 @@
}
return got_icmp;
}
+static jfieldID IO_fd_fdID = NULL;
+static jfieldID pdsi_fdID = NULL;
+
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: initIDs
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_initIDs
(JNIEnv *env, jclass clazz)
{
+ pdsi_fdID = (*env)->GetFieldID(env, clazz, "fd",
+ "Ljava/io/FileDescriptor;");
+ CHECK_NULL(pdsi_fdID);
+ IO_fd_fdID = NET_GetFileDescriptorID(env);
+ CHECK_NULL(IO_fd_fdID);
+ JNU_CHECK_EXCEPTION(env);
+
initInetAddressIDs(env);
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
@@ -501,5 +511,34 @@
return -1;
}
return result;
}
+
+/*
+ * Class: java_net_DualStackPlainDatagramSocketImpl
+ * Method: dataAvailable
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_dataAvailable
+(JNIEnv *env, jobject this) {
+ SOCKET fd;
+ int rv = -1;
+ jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
+
+ if (!IS_NULL(fdObj)) {
+ int retval = 0;
+ fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
+ rv = ioctlsocket(fd, FIONREAD, &retval);
+ if (retval > 0) {
+ return retval;
+ }
+ }
+
+ if (rv < 0) {
+ JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+ "Socket closed");
+ return -1;
+ }
+
+ return 0;
+}
< prev index next >