changeset 4702:926b1d1014cf

7122794: (macosx) DatagramSocket.disconnect() not working Reviewed-by: chegar
author michaelm
date Mon, 30 Jan 2012 13:49:56 +0000
parents d476c80173a3
children ebeb9c8e0bb8
files src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java src/share/classes/java/net/DatagramSocket.java
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Mon Jan 30 13:47:44 2012 +0000
+++ b/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Mon Jan 30 13:49:56 2012 +0000
@@ -28,6 +28,7 @@
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.Enumeration;
+import java.security.AccessController;
 import sun.net.ResourceManager;
 
 /**
@@ -54,6 +55,15 @@
     private boolean loopbackMode = true;
     private int ttl = -1;
 
+    private static final String os = AccessController.doPrivileged(
+        new sun.security.action.GetPropertyAction("os.name")
+    );
+
+    /**
+     * flag set if the native connect() call not to be used
+     */
+    private final static boolean connectDisabled = os.startsWith("Mac OS");
+
     /**
      * Load net library into runtime.
      */
@@ -349,4 +359,7 @@
     protected abstract void connect0(InetAddress address, int port) throws SocketException;
     protected abstract void disconnect0(int family);
 
+    protected boolean nativeConnectDisabled() {
+        return connectDisabled;
+    }
 }
--- a/src/share/classes/java/net/DatagramSocket.java	Mon Jan 30 13:47:44 2012 +0000
+++ b/src/share/classes/java/net/DatagramSocket.java	Mon Jan 30 13:49:56 2012 +0000
@@ -135,7 +135,8 @@
           bind(new InetSocketAddress(0));
 
         // old impls do not support connect/disconnect
-        if (oldImpl) {
+        if (oldImpl || (impl instanceof AbstractPlainDatagramSocketImpl &&
+             ((AbstractPlainDatagramSocketImpl)impl).nativeConnectDisabled())) {
             connectState = ST_CONNECTED_NO_IMPL;
         } else {
             try {