8166584: Remove obsolete utility function NET_ThrowSocketException in windows libnet
authorclanger
Wed, 28 Sep 2016 15:47:03 +0200
changeset 41210 73593ed418ff
parent 41209 1e31fbc26987
child 41211 744278856e58
8166584: Remove obsolete utility function NET_ThrowSocketException in windows libnet Reviewed-by: chegar
jdk/src/java.base/unix/native/libnet/SocketInputStream.c
jdk/src/java.base/windows/native/libnet/SocketInputStream.c
jdk/src/java.base/windows/native/libnet/net_util_md.c
jdk/src/java.base/windows/native/libnet/net_util_md.h
--- a/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Wed Sep 28 14:29:35 2016 +0200
+++ b/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Wed Sep 28 15:47:03 2016 +0200
@@ -58,15 +58,15 @@
         result = NET_TimeoutWithCurrentTime(fd, timeout, prevtime);
         if (result <= 0) {
             if (result == 0) {
-                JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", "Read timed out");
+                JNU_ThrowByName(env, "java/net/SocketTimeoutException", "Read timed out");
             } else if (result == -1) {
                 if (errno == EBADF) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
+                    JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
                 } else if (errno == ENOMEM) {
                     JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
                 } else {
                     JNU_ThrowByNameWithMessageAndLastError
-                            (env, JNU_JAVANETPKG "SocketException", "select/poll failed");
+                            (env, "java/net/SocketException", "select/poll failed");
                 }
             }
             return -1;
@@ -100,19 +100,14 @@
     jint fd, nread;
 
     if (IS_NULL(fdObj)) {
-        /* shouldn't this be a NullPointerException? -br */
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+        JNU_ThrowByName(env, "java/net/SocketException",
                         "Socket closed");
         return -1;
-    } else {
-        fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
-        /* Bug 4086704 - If the Socket associated with this file descriptor
-         * was closed (sysCloseFD), then the file descriptor is set to -1.
-         */
-        if (fd == -1) {
-            JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
-            return -1;
-        }
+    }
+    fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
+    if (fd == -1) {
+        JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
+        return -1;
     }
 
     /*
@@ -154,17 +149,17 @@
                     break;
 
                 case EBADF:
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                    JNU_ThrowByName(env, "java/net/SocketException",
                         "Socket closed");
                     break;
 
                 case EINTR:
-                     JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
+                     JNU_ThrowByName(env, "java/io/InterruptedIOException",
                            "Operation interrupted");
                      break;
                 default:
                     JNU_ThrowByNameWithMessageAndLastError
-                        (env, JNU_JAVANETPKG "SocketException", "Read failed");
+                        (env, "java/net/SocketException", "Read failed");
             }
         }
     } else {
--- a/jdk/src/java.base/windows/native/libnet/SocketInputStream.c	Wed Sep 28 14:29:35 2016 +0200
+++ b/jdk/src/java.base/windows/native/libnet/SocketInputStream.c	Wed Sep 28 15:47:03 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -62,18 +62,18 @@
                                             jobject fdObj, jbyteArray data,
                                             jint off, jint len, jint timeout)
 {
+    char BUF[MAX_BUFFER_LEN];
     char *bufP;
-    char BUF[MAX_BUFFER_LEN];
-    jint fd, newfd;
-    jint nread;
+    jint fd, newfd, nread;
 
     if (IS_NULL(fdObj)) {
-        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
+        JNU_ThrowByName(env, "java/net/SocketException",
+                        "Socket closed");
         return -1;
     }
     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
     if (fd == -1) {
-        NET_ThrowSocketException(env, "Socket closed");
+        JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
         return -1;
     }
 
@@ -103,10 +103,10 @@
 
             if (ret <= 0) {
                 if (ret == 0) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                    JNU_ThrowByName(env, "java/net/SocketTimeoutException",
                                     "Read timed out");
                 } else if (ret == -1) {
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
+                    JNU_ThrowByName(env, "java/net/SocketException", "socket closed");
                 }
                 if (bufP != BUF) {
                     free(bufP);
@@ -117,7 +117,7 @@
             /*check if the socket has been closed while we were in timeout*/
             newfd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
             if (newfd == -1) {
-                NET_ThrowSocketException(env, "Socket Closed");
+                JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
                 if (bufP != BUF) {
                     free(bufP);
                 }
@@ -134,11 +134,11 @@
             // Check if the socket has been closed since we last checked.
             // This could be a reason for recv failing.
             if ((*env)->GetIntField(env, fdObj, IO_fd_fdID) == -1) {
-                NET_ThrowSocketException(env, "Socket closed");
+                JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
             } else {
                 switch (WSAGetLastError()) {
                     case WSAEINTR:
-                        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
+                        JNU_ThrowByName(env, "java/net/SocketException",
                             "socket closed");
                         break;
 
@@ -153,7 +153,7 @@
                         break;
 
                     case WSAETIMEDOUT :
-                        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
+                        JNU_ThrowByName(env, "java/net/SocketTimeoutException",
                                        "Read timed out");
                         break;
 
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.c	Wed Sep 28 14:29:35 2016 +0200
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.c	Wed Sep 28 15:47:03 2016 +0200
@@ -203,19 +203,6 @@
 }
 
 void
-NET_ThrowSocketException(JNIEnv *env, char* msg)
-{
-    static jclass cls = NULL;
-    if (cls == NULL) {
-        cls = (*env)->FindClass(env, "java/net/SocketException");
-        CHECK_NULL(cls);
-        cls = (*env)->NewGlobalRef(env, cls);
-        CHECK_NULL(cls);
-    }
-    (*env)->ThrowNew(env, cls, msg);
-}
-
-void
 NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
                    const char *defaultDetail) {
     char errmsg[255];
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.h	Wed Sep 28 14:29:35 2016 +0200
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.h	Wed Sep 28 15:47:03 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -299,8 +299,6 @@
 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
          const char *defaultDetail);
 
-void NET_ThrowSocketException(JNIEnv *env, char* msg);
-
 /*
  * differs from NET_Timeout() as follows:
  *