changeset 4629:1e89a13d9d8f

7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc() Reviewed-by: michaelm
author chegar
date Mon, 10 Oct 2011 10:38:35 +0100
parents 2edaef22de23
children 2a36b8741363
files src/share/classes/java/net/AbstractPlainSocketImpl.java src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
diffstat 3 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/AbstractPlainSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/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/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/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/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java	Fri Oct 07 14:09:53 2011 +0100
+++ b/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;
+        }
     }
 
      /**