author | redestad |
Thu, 21 Apr 2016 13:39:53 +0200 | |
changeset 37593 | 824750ada3d6 |
parent 37354 | 2cc8c7bd70ee |
child 37781 | 71ed5645f17c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package java.net; |
|
26 |
||
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37354
diff
changeset
|
27 |
import java.util.Properties; |
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
28 |
import sun.security.action.GetPropertyAction; |
2 | 29 |
|
30 |
/** |
|
31 |
* This class defines a factory for creating DatagramSocketImpls. It defaults |
|
32 |
* to creating plain DatagramSocketImpls, but may create other DatagramSocketImpls |
|
33 |
* by setting the impl.prefix system property. |
|
34 |
* |
|
35 |
* For Windows versions lower than Windows Vista a TwoStacksPlainDatagramSocketImpl |
|
36 |
* is always created. This impl supports IPv6 on these platform where available. |
|
37 |
* |
|
38 |
* On Windows platforms greater than Vista that support a dual layer TCP/IP stack |
|
39 |
* a DualStackPlainDatagramSocketImpl is created for DatagramSockets. For MulticastSockets |
|
40 |
* a TwoStacksPlainDatagramSocketImpl is always created. This is to overcome the lack |
|
41 |
* of behavior defined for multicasting over a dual layer socket by the RFC. |
|
42 |
* |
|
43 |
* @author Chris Hegarty |
|
44 |
*/ |
|
45 |
||
46 |
class DefaultDatagramSocketImplFactory |
|
47 |
{ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32503
diff
changeset
|
48 |
private static final Class<?> prefixImplClass; |
2 | 49 |
|
50 |
/* java.net.preferIPv4Stack */ |
|
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
51 |
private static final boolean preferIPv4Stack; |
18192 | 52 |
|
53 |
/* True if exclusive binding is on for Windows */ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32503
diff
changeset
|
54 |
private static final boolean exclusiveBind; |
18192 | 55 |
|
2 | 56 |
static { |
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
57 |
Class<?> prefixImplClassLocal = null; |
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
58 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37354
diff
changeset
|
59 |
Properties props = GetPropertyAction.getProperties(); |
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
60 |
preferIPv4Stack = Boolean.parseBoolean( |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37354
diff
changeset
|
61 |
props.getProperty("java.net.preferIPv4Stack")); |
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
62 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37354
diff
changeset
|
63 |
String exclBindProp = props.getProperty("sun.net.useExclusiveBind", ""); |
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
64 |
exclusiveBind = (exclBindProp.isEmpty()) |
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
65 |
? true |
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
66 |
: Boolean.parseBoolean(exclBindProp); |
2 | 67 |
|
68 |
// impl.prefix |
|
69 |
String prefix = null; |
|
70 |
try { |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37354
diff
changeset
|
71 |
prefix = props.getProperty("impl.prefix"); |
2 | 72 |
if (prefix != null) |
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
73 |
prefixImplClassLocal = Class.forName("java.net."+prefix+"DatagramSocketImpl"); |
2 | 74 |
} catch (Exception e) { |
75 |
System.err.println("Can't find class: java.net." + |
|
76 |
prefix + |
|
77 |
"DatagramSocketImpl: check impl.prefix property"); |
|
78 |
} |
|
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
79 |
|
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
80 |
prefixImplClass = prefixImplClassLocal; |
2 | 81 |
} |
82 |
||
83 |
/** |
|
84 |
* Creates a new <code>DatagramSocketImpl</code> instance. |
|
85 |
* |
|
86 |
* @param isMulticast true if this impl is to be used for a MutlicastSocket |
|
87 |
* @return a new instance of <code>PlainDatagramSocketImpl</code>. |
|
88 |
*/ |
|
89 |
static DatagramSocketImpl createDatagramSocketImpl(boolean isMulticast) |
|
90 |
throws SocketException { |
|
91 |
if (prefixImplClass != null) { |
|
92 |
try { |
|
93 |
return (DatagramSocketImpl) prefixImplClass.newInstance(); |
|
94 |
} catch (Exception e) { |
|
95 |
throw new SocketException("can't instantiate DatagramSocketImpl"); |
|
96 |
} |
|
97 |
} else { |
|
37354
2cc8c7bd70ee
8154185: Drop code to support Windows XP in DefaultDatagramSocketImplFactory
redestad
parents:
32649
diff
changeset
|
98 |
if (!preferIPv4Stack && !isMulticast) |
18192 | 99 |
return new DualStackPlainDatagramSocketImpl(exclusiveBind); |
2 | 100 |
else |
32503
1478c9130534
8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents:
25859
diff
changeset
|
101 |
return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast); |
2 | 102 |
} |
103 |
} |
|
104 |
} |