< prev index next >
src/java.base/windows/classes/java/net/DefaultDatagramSocketImplFactory.java
Print this page
rev 12681 : [mq]: 8072466-Deadlock-when-starting-MulticastSocket-and-DatagramSocket
*** 1,7 ****
/*
! * Copyright (c) 2007, 2013, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2007, 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 43,71 ****
* @author Chris Hegarty
*/
class DefaultDatagramSocketImplFactory
{
! static Class<?> prefixImplClass = null;
/* the windows version. */
private static float version;
/* java.net.preferIPv4Stack */
private static boolean preferIPv4Stack = false;
/* If the version supports a dual stack TCP implementation */
! private static boolean useDualStackImpl = false;
/* sun.net.useExclusiveBind */
private static String exclBindProp;
/* True if exclusive binding is on for Windows */
! private static boolean exclusiveBind = true;
!
static {
// Determine Windows Version.
java.security.AccessController.doPrivileged(
new PrivilegedAction<Object>() {
public Object run() {
version = 0;
--- 43,74 ----
* @author Chris Hegarty
*/
class DefaultDatagramSocketImplFactory
{
! private final static Class<?> prefixImplClass;
/* the windows version. */
private static float version;
/* java.net.preferIPv4Stack */
private static boolean preferIPv4Stack = false;
/* If the version supports a dual stack TCP implementation */
! private final static boolean useDualStackImpl;
/* sun.net.useExclusiveBind */
private static String exclBindProp;
/* True if exclusive binding is on for Windows */
! private final static boolean exclusiveBind;
static {
+ Class<?> prefixImplClassLocal = null;
+ boolean useDualStackImplLocal = false;
+ boolean exclusiveBindLocal = true;
+
// Determine Windows Version.
java.security.AccessController.doPrivileged(
new PrivilegedAction<Object>() {
public Object run() {
version = 0;
*** 76,116 ****
System.getProperties()
.getProperty(
"java.net.preferIPv4Stack"));
exclBindProp = System.getProperty(
"sun.net.useExclusiveBind");
! } catch (NumberFormatException e ) {
assert false : e;
}
return null; // nothing to return
}
});
// (version >= 6.0) implies Vista or greater.
if (version >= 6.0 && !preferIPv4Stack) {
! useDualStackImpl = true;
}
if (exclBindProp != null) {
// sun.net.useExclusiveBind is true
! exclusiveBind = exclBindProp.length() == 0 ? true
: Boolean.parseBoolean(exclBindProp);
} else if (version < 6.0) {
! exclusiveBind = false;
}
// impl.prefix
String prefix = null;
try {
prefix = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("impl.prefix", null));
if (prefix != null)
! prefixImplClass = Class.forName("java.net."+prefix+"DatagramSocketImpl");
} catch (Exception e) {
System.err.println("Can't find class: java.net." +
prefix +
"DatagramSocketImpl: check impl.prefix property");
}
}
/**
* Creates a new <code>DatagramSocketImpl</code> instance.
*
--- 79,123 ----
System.getProperties()
.getProperty(
"java.net.preferIPv4Stack"));
exclBindProp = System.getProperty(
"sun.net.useExclusiveBind");
! } catch (NumberFormatException e) {
assert false : e;
}
return null; // nothing to return
}
});
// (version >= 6.0) implies Vista or greater.
if (version >= 6.0 && !preferIPv4Stack) {
! useDualStackImplLocal = true;
}
if (exclBindProp != null) {
// sun.net.useExclusiveBind is true
! exclusiveBindLocal = exclBindProp.length() == 0 ? true
: Boolean.parseBoolean(exclBindProp);
} else if (version < 6.0) {
! exclusiveBindLocal = false;
}
// impl.prefix
String prefix = null;
try {
prefix = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("impl.prefix", null));
if (prefix != null)
! prefixImplClassLocal = Class.forName("java.net."+prefix+"DatagramSocketImpl");
} catch (Exception e) {
System.err.println("Can't find class: java.net." +
prefix +
"DatagramSocketImpl: check impl.prefix property");
}
+
+ prefixImplClass = prefixImplClassLocal;
+ useDualStackImpl = useDualStackImplLocal;
+ exclusiveBind = exclusiveBindLocal;
}
/**
* Creates a new <code>DatagramSocketImpl</code> instance.
*
*** 124,137 ****
return (DatagramSocketImpl) prefixImplClass.newInstance();
} catch (Exception e) {
throw new SocketException("can't instantiate DatagramSocketImpl");
}
} else {
- if (isMulticast)
- exclusiveBind = false;
if (useDualStackImpl && !isMulticast)
return new DualStackPlainDatagramSocketImpl(exclusiveBind);
else
! return new TwoStacksPlainDatagramSocketImpl(exclusiveBind);
}
}
}
--- 131,142 ----
return (DatagramSocketImpl) prefixImplClass.newInstance();
} catch (Exception e) {
throw new SocketException("can't instantiate DatagramSocketImpl");
}
} else {
if (useDualStackImpl && !isMulticast)
return new DualStackPlainDatagramSocketImpl(exclusiveBind);
else
! return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast);
}
}
}
< prev index next >