changeset 8155:2ee54b1c7203 jdk7u72-b09

Merge
author coffeys
date Mon, 11 Aug 2014 18:13:07 +0100
parents ceb50d7c081d (current diff) 7e47a971eff7 (diff)
children 40d05be7580b
files
diffstat 3 files changed, 61 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/DatagramSocket.java	Fri Aug 08 15:06:39 2014 +0400
+++ b/src/share/classes/java/net/DatagramSocket.java	Mon Aug 11 18:13:07 2014 +0100
@@ -773,6 +773,7 @@
                     } // end of while
                 }
             }
+            DatagramPacket tmp = null;
             if ((connectState == ST_CONNECTED_NO_IMPL) || explicitFilter) {
                 // We have to do the filtering the old fashioned way since
                 // the native impl doesn't support connect or the connect
@@ -797,15 +798,11 @@
                     if ((!connectedAddress.equals(peekAddress)) ||
                         (connectedPort != peekPort)) {
                         // throw the packet away and silently continue
-                        DatagramPacket tmp = new DatagramPacket(
+                        tmp = new DatagramPacket(
                                                 new byte[1024], 1024);
                         getImpl().receive(tmp);
                         if (explicitFilter) {
-                            bytesLeftToFilter -= tmp.getLength();
-                            if (bytesLeftToFilter <= 0 ||
-                                getImpl().dataAvailable() <= 0)
-                            {
-                                explicitFilter = false;
+                            if (checkFiltering(tmp)) {
                                 stop = true;
                             }
                         }
@@ -817,9 +814,23 @@
             // If the security check succeeds, or the datagram is
             // connected then receive the packet
             getImpl().receive(p);
+            if (explicitFilter && tmp == null) {
+                // packet was not filtered, account for it here
+                checkFiltering(p);
+            }
         }
     }
 
+    // Update the filter information and return true if finished
+    private boolean checkFiltering(DatagramPacket p) throws SocketException {
+        bytesLeftToFilter -= p.getLength();
+        if (bytesLeftToFilter <= 0 || getImpl().dataAvailable() <= 0) {
+            explicitFilter = false;
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Gets the local address to which the socket is bound.
      *
--- a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Fri Aug 08 15:06:39 2014 +0400
+++ b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Mon Aug 11 18:13:07 2014 +0100
@@ -764,7 +764,7 @@
                             }
                             do {
                                 tmpBuf.clear();
-                            } while (read(tmpBuf) > 0);
+                            } while (receive(tmpBuf) != null);
                         } finally {
                             if (blocking) {
                                 configureBlocking(true);
--- a/src/windows/native/java/net/AbstractPlainDatagramSocketImpl.c	Fri Aug 08 15:06:39 2014 +0400
+++ b/src/windows/native/java/net/AbstractPlainDatagramSocketImpl.c	Mon Aug 11 18:13:07 2014 +0100
@@ -32,9 +32,11 @@
 
 #include "java_net_AbstractPlainDatagramSocketImpl.h"
 
-static jfieldID IO_fd_fdID;
+static jfieldID IO_fd_fdID = NULL;
+static jfieldID apdsi_fdID = NULL;
 
-static jfieldID apdsi_fdID;
+static jfieldID apdsi_fd1ID = NULL;
+static jclass two_stacks_clazz = NULL;
 
 
 /*
@@ -48,9 +50,20 @@
     apdsi_fdID = (*env)->GetFieldID(env, cls, "fd",
                                    "Ljava/io/FileDescriptor;");
     CHECK_NULL(apdsi_fdID);
-
     IO_fd_fdID = NET_GetFileDescriptorID(env);
     CHECK_NULL(IO_fd_fdID);
+
+    two_stacks_clazz = (*env)->FindClass(env, "java/net/TwoStacksPlainDatagramSocketImpl");
+    CHECK_NULL(two_stacks_clazz);
+
+    /* Handle both TwoStacks and DualStack here */
+
+    if (JNU_Equals(env, cls, two_stacks_clazz)) {
+        /* fd1 present only in TwoStack.. */
+        apdsi_fd1ID = (*env)->GetFieldID(env, cls, "fd1",
+                                   "Ljava/io/FileDescriptor;");
+        CHECK_NULL(apdsi_fd1ID);
+    }
 }
 
 /*
@@ -61,20 +74,38 @@
 JNIEXPORT jint JNICALL Java_java_net_AbstractPlainDatagramSocketImpl_dataAvailable
 (JNIEnv *env, jobject this) {
     SOCKET fd;
-    int  retval;
-
+    SOCKET fd1;
+    int  rv = -1, rv1 = -1;
     jobject fdObj = (*env)->GetObjectField(env, this, apdsi_fdID);
 
-    if (IS_NULL(fdObj)) {
+    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 (!IS_NULL(apdsi_fd1ID)) {
+        /* TwoStacks */
+        jobject fd1Obj = (*env)->GetObjectField(env, this, apdsi_fd1ID);
+        if (!IS_NULL(fd1Obj)) {
+            int retval = 0;
+            fd1 = (SOCKET)(*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
+            rv1 = ioctlsocket(fd1, FIONREAD, &retval);
+            if (retval > 0) {
+                return retval;
+            }
+        }
+    }
+
+    if (rv < 0 && rv1 < 0) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
-                        "Socket closed");
+                            "Socket closed");
         return -1;
     }
-    fd = (SOCKET)(*env)->GetIntField(env, fdObj, IO_fd_fdID);
 
-    if (ioctlsocket(fd, FIONREAD, &retval) < 0) {
-        return -1;
-    }
-    return retval;
+    return 0;
 }