52 private static boolean preferIPv4Stack = false; |
52 private static boolean preferIPv4Stack = false; |
53 |
53 |
54 /* If the version supports a dual stack TCP implementation */ |
54 /* If the version supports a dual stack TCP implementation */ |
55 private static boolean useDualStackImpl = false; |
55 private static boolean useDualStackImpl = false; |
56 |
56 |
|
57 /* sun.net.useExclusiveBind */ |
|
58 private static String exclBindProp; |
|
59 |
|
60 /* True if exclusive binding is on for Windows */ |
|
61 private static boolean exclusiveBind = true; |
|
62 |
57 static { |
63 static { |
58 java.security.AccessController.doPrivileged( new PrivilegedAction<Object>() { |
64 java.security.AccessController.doPrivileged( new PrivilegedAction<Object>() { |
59 public Object run() { |
65 public Object run() { |
60 version = 0; |
66 version = 0; |
61 try { |
67 try { |
62 version = Float.parseFloat(System.getProperties().getProperty("os.version")); |
68 version = Float.parseFloat(System.getProperties().getProperty("os.version")); |
63 preferIPv4Stack = Boolean.parseBoolean( |
69 preferIPv4Stack = Boolean.parseBoolean( |
64 System.getProperties().getProperty("java.net.preferIPv4Stack")); |
70 System.getProperties().getProperty("java.net.preferIPv4Stack")); |
|
71 exclBindProp = System.getProperty("sun.net.useExclusiveBind"); |
65 } catch (NumberFormatException e ) { |
72 } catch (NumberFormatException e ) { |
66 assert false : e; |
73 assert false : e; |
67 } |
74 } |
68 return null; // nothing to return |
75 return null; // nothing to return |
69 } }); |
76 } }); |
70 |
77 |
71 // (version >= 6.0) implies Vista or greater. |
78 // (version >= 6.0) implies Vista or greater. |
72 if (version >= 6.0 && !preferIPv4Stack) { |
79 if (version >= 6.0 && !preferIPv4Stack) { |
73 useDualStackImpl = true; |
80 useDualStackImpl = true; |
|
81 } |
|
82 |
|
83 if (exclBindProp != null) { |
|
84 // sun.net.useExclusiveBind is true |
|
85 exclusiveBind = exclBindProp.length() == 0 ? true |
|
86 : Boolean.parseBoolean(exclBindProp); |
|
87 } else if (version < 6.0) { |
|
88 exclusiveBind = false; |
74 } |
89 } |
75 } |
90 } |
76 |
91 |
77 /** |
92 /** |
78 * Constructs an empty instance. |
93 * Constructs an empty instance. |
79 */ |
94 */ |
80 PlainSocketImpl() { |
95 PlainSocketImpl() { |
81 if (useDualStackImpl) { |
96 if (useDualStackImpl) { |
82 impl = new DualStackPlainSocketImpl(); |
97 impl = new DualStackPlainSocketImpl(exclusiveBind); |
83 } else { |
98 } else { |
84 impl = new TwoStacksPlainSocketImpl(); |
99 impl = new TwoStacksPlainSocketImpl(exclusiveBind); |
85 } |
100 } |
86 } |
101 } |
87 |
102 |
88 /** |
103 /** |
89 * Constructs an instance with the given file descriptor. |
104 * Constructs an instance with the given file descriptor. |
90 */ |
105 */ |
91 PlainSocketImpl(FileDescriptor fd) { |
106 PlainSocketImpl(FileDescriptor fd) { |
92 if (useDualStackImpl) { |
107 if (useDualStackImpl) { |
93 impl = new DualStackPlainSocketImpl(fd); |
108 impl = new DualStackPlainSocketImpl(fd, exclusiveBind); |
94 } else { |
109 } else { |
95 impl = new TwoStacksPlainSocketImpl(fd); |
110 impl = new TwoStacksPlainSocketImpl(fd, exclusiveBind); |
96 } |
111 } |
97 } |
112 } |
98 |
113 |
99 // Override methods in SocketImpl that access impl's fields. |
114 // Override methods in SocketImpl that access impl's fields. |
100 |
115 |