7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
authorchegar
Mon, 10 Oct 2011 10:38:35 +0100
changeset 10704 db5816a6e8c7
parent 10703 5e4b04df89ec
child 10705 c059c562bad2
7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc() Reviewed-by: michaelm
jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
jdk/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java
jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
--- a/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java	Mon Oct 10 10:38:35 2011 +0100
@@ -86,10 +86,11 @@
      * is a stream socket (true) or an unconnected UDP socket (false).
      */
     protected synchronized void create(boolean stream) throws IOException {
-        fd = new FileDescriptor();
         this.stream = stream;
         if (!stream) {
             ResourceManager.beforeUdpCreate();
+            // only create the fd after we know we will be able to create the socket
+            fd = new FileDescriptor();
             try {
                 socketCreate(false);
             } catch (IOException ioe) {
@@ -98,6 +99,7 @@
                 throw ioe;
             }
         } else {
+            fd = new FileDescriptor();
             socketCreate(true);
         }
         if (socket != null)
--- a/jdk/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/jdk/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java	Mon Oct 10 10:38:35 2011 +0100
@@ -70,7 +70,7 @@
         fd1 = new FileDescriptor();
         try {
             super.create();
-        } catch (IOException e) {
+        } catch (SocketException e) {
             fd1 = null;
             throw e;
         }
--- a/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java	Mon Oct 10 10:38:35 2011 +0100
@@ -81,7 +81,12 @@
      */
     protected synchronized void create(boolean stream) throws IOException {
         fd1 = new FileDescriptor();
-        super.create(stream);
+        try {
+            super.create();
+        } catch (IOException e) {
+            fd1 = null;
+            throw e;
+        }
     }
 
      /**