author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55375 | 96c7427456f9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, 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 |
||
26 |
package sun.nio.ch; |
|
27 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
28 |
import java.io.FileDescriptor; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
29 |
import java.io.IOException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
30 |
import java.net.Inet4Address; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
31 |
import java.net.Inet6Address; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
32 |
import java.net.InetAddress; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
33 |
import java.net.InetSocketAddress; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
34 |
import java.net.NetworkInterface; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
35 |
import java.net.ProtocolFamily; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
36 |
import java.net.SocketAddress; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
37 |
import java.net.SocketException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
38 |
import java.net.SocketOption; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
39 |
import java.net.StandardProtocolFamily; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
40 |
import java.net.StandardSocketOptions; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
41 |
import java.net.UnknownHostException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
42 |
import java.nio.channels.AlreadyBoundException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
43 |
import java.nio.channels.ClosedChannelException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
44 |
import java.nio.channels.NotYetBoundException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
45 |
import java.nio.channels.NotYetConnectedException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
46 |
import java.nio.channels.UnresolvedAddressException; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
47 |
import java.nio.channels.UnsupportedAddressTypeException; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
48 |
import java.security.AccessController; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
49 |
import java.security.PrivilegedAction; |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
50 |
import java.util.Enumeration; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
51 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
52 |
import sun.net.ext.ExtendedSocketOptions; |
55375 | 53 |
import sun.net.util.IPAddressUtil; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36115
diff
changeset
|
54 |
import sun.security.action.GetPropertyAction; |
2 | 55 |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
9679
diff
changeset
|
56 |
public class Net { |
2 | 57 |
|
58 |
private Net() { } |
|
59 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
60 |
// unspecified protocol family |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
61 |
static final ProtocolFamily UNSPEC = new ProtocolFamily() { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
62 |
public String name() { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
63 |
return "UNSPEC"; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
64 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
65 |
}; |
2 | 66 |
|
18192 | 67 |
// set to true if exclusive binding is on for Windows |
68 |
private static final boolean exclusiveBind; |
|
69 |
||
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
70 |
// set to true if the fast tcp loopback should be enabled on Windows |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
71 |
private static final boolean fastLoopback; |
18192 | 72 |
|
2 | 73 |
// -- Miscellaneous utilities -- |
74 |
||
34774
03b4e6dc367b
8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents:
32649
diff
changeset
|
75 |
private static volatile boolean checkedIPv6; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
76 |
private static volatile boolean isIPv6Available; |
36115 | 77 |
private static volatile boolean checkedReusePort; |
78 |
private static volatile boolean isReusePortAvailable; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
79 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
80 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
81 |
* Tells whether dual-IPv4/IPv6 sockets should be used. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
82 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
83 |
static boolean isIPv6Available() { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
84 |
if (!checkedIPv6) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
85 |
isIPv6Available = isIPv6Available0(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
86 |
checkedIPv6 = true; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
87 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
88 |
return isIPv6Available; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
89 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
90 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
91 |
/** |
36115 | 92 |
* Tells whether SO_REUSEPORT is supported. |
93 |
*/ |
|
94 |
static boolean isReusePortAvailable() { |
|
95 |
if (!checkedReusePort) { |
|
96 |
isReusePortAvailable = isReusePortAvailable0(); |
|
97 |
checkedReusePort = true; |
|
98 |
} |
|
99 |
return isReusePortAvailable; |
|
100 |
} |
|
101 |
||
102 |
/** |
|
18192 | 103 |
* Returns true if exclusive binding is on |
104 |
*/ |
|
105 |
static boolean useExclusiveBind() { |
|
106 |
return exclusiveBind; |
|
107 |
} |
|
108 |
||
109 |
/** |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
110 |
* Tells whether IPv6 sockets can join IPv4 multicast groups |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
111 |
*/ |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
112 |
static boolean canIPv6SocketJoinIPv4Group() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
113 |
return canIPv6SocketJoinIPv4Group0(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
114 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
115 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
116 |
/** |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
117 |
* Tells whether {@link #join6} can be used to join an IPv4 |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
118 |
* multicast group (IPv4 group as IPv4-mapped IPv6 address) |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
119 |
*/ |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
120 |
static boolean canJoin6WithIPv4Group() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
121 |
return canJoin6WithIPv4Group0(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
122 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
123 |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
9679
diff
changeset
|
124 |
public static InetSocketAddress checkAddress(SocketAddress sa) { |
2 | 125 |
if (sa == null) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
126 |
throw new NullPointerException(); |
2 | 127 |
if (!(sa instanceof InetSocketAddress)) |
128 |
throw new UnsupportedAddressTypeException(); // ## needs arg |
|
129 |
InetSocketAddress isa = (InetSocketAddress)sa; |
|
130 |
if (isa.isUnresolved()) |
|
131 |
throw new UnresolvedAddressException(); // ## needs arg |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
2057
diff
changeset
|
132 |
InetAddress addr = isa.getAddress(); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
2057
diff
changeset
|
133 |
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
2057
diff
changeset
|
134 |
throw new IllegalArgumentException("Invalid address type"); |
2 | 135 |
return isa; |
136 |
} |
|
137 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
138 |
static InetSocketAddress checkAddress(SocketAddress sa, ProtocolFamily family) { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
139 |
InetSocketAddress isa = checkAddress(sa); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
140 |
if (family == StandardProtocolFamily.INET) { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
141 |
InetAddress addr = isa.getAddress(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
142 |
if (!(addr instanceof Inet4Address)) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
143 |
throw new UnsupportedAddressTypeException(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
144 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
145 |
return isa; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
146 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
47216
diff
changeset
|
147 |
|
2 | 148 |
static InetSocketAddress asInetSocketAddress(SocketAddress sa) { |
149 |
if (!(sa instanceof InetSocketAddress)) |
|
150 |
throw new UnsupportedAddressTypeException(); |
|
151 |
return (InetSocketAddress)sa; |
|
152 |
} |
|
153 |
||
154 |
static void translateToSocketException(Exception x) |
|
155 |
throws SocketException |
|
156 |
{ |
|
157 |
if (x instanceof SocketException) |
|
158 |
throw (SocketException)x; |
|
159 |
Exception nx = x; |
|
160 |
if (x instanceof ClosedChannelException) |
|
161 |
nx = new SocketException("Socket is closed"); |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
162 |
else if (x instanceof NotYetConnectedException) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
163 |
nx = new SocketException("Socket is not connected"); |
2 | 164 |
else if (x instanceof AlreadyBoundException) |
165 |
nx = new SocketException("Already bound"); |
|
166 |
else if (x instanceof NotYetBoundException) |
|
167 |
nx = new SocketException("Socket is not bound yet"); |
|
168 |
else if (x instanceof UnsupportedAddressTypeException) |
|
169 |
nx = new SocketException("Unsupported address type"); |
|
170 |
else if (x instanceof UnresolvedAddressException) { |
|
171 |
nx = new SocketException("Unresolved address"); |
|
172 |
} |
|
173 |
if (nx != x) |
|
174 |
nx.initCause(x); |
|
175 |
||
176 |
if (nx instanceof SocketException) |
|
177 |
throw (SocketException)nx; |
|
178 |
else if (nx instanceof RuntimeException) |
|
179 |
throw (RuntimeException)nx; |
|
180 |
else |
|
181 |
throw new Error("Untranslated exception", nx); |
|
182 |
} |
|
183 |
||
184 |
static void translateException(Exception x, |
|
185 |
boolean unknownHostForUnresolved) |
|
186 |
throws IOException |
|
187 |
{ |
|
188 |
if (x instanceof IOException) |
|
189 |
throw (IOException)x; |
|
190 |
// Throw UnknownHostException from here since it cannot |
|
191 |
// be thrown as a SocketException |
|
192 |
if (unknownHostForUnresolved && |
|
193 |
(x instanceof UnresolvedAddressException)) |
|
194 |
{ |
|
195 |
throw new UnknownHostException(); |
|
196 |
} |
|
197 |
translateToSocketException(x); |
|
198 |
} |
|
199 |
||
200 |
static void translateException(Exception x) |
|
201 |
throws IOException |
|
202 |
{ |
|
203 |
translateException(x, false); |
|
204 |
} |
|
205 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
206 |
/** |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
207 |
* Returns the local address after performing a SecurityManager#checkConnect. |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
208 |
*/ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
209 |
static InetSocketAddress getRevealedLocalAddress(InetSocketAddress addr) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
210 |
SecurityManager sm = System.getSecurityManager(); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
211 |
if (addr == null || sm == null) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
212 |
return addr; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
213 |
|
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
214 |
try{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
215 |
sm.checkConnect(addr.getAddress().getHostAddress(), -1); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
216 |
// Security check passed |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
217 |
} catch (SecurityException e) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
218 |
// Return loopback address only if security check fails |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
219 |
addr = getLoopbackAddress(addr.getPort()); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
220 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
221 |
return addr; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
222 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
223 |
|
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
224 |
static String getRevealedLocalAddressAsString(InetSocketAddress addr) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
225 |
return System.getSecurityManager() == null ? addr.toString() : |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
226 |
getLoopbackAddress(addr.getPort()).toString(); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
227 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
228 |
|
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
229 |
private static InetSocketAddress getLoopbackAddress(int port) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
230 |
return new InetSocketAddress(InetAddress.getLoopbackAddress(), |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
231 |
port); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
232 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
233 |
|
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
234 |
/** |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
235 |
* Returns any IPv4 address of the given network interface, or |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
236 |
* null if the interface does not have any IPv4 addresses. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
237 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
238 |
static Inet4Address anyInet4Address(final NetworkInterface interf) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
239 |
return AccessController.doPrivileged(new PrivilegedAction<Inet4Address>() { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
240 |
public Inet4Address run() { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
241 |
Enumeration<InetAddress> addrs = interf.getInetAddresses(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
242 |
while (addrs.hasMoreElements()) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
243 |
InetAddress addr = addrs.nextElement(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
244 |
if (addr instanceof Inet4Address) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
245 |
return (Inet4Address)addr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
246 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
247 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
248 |
return null; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
249 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
250 |
}); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
251 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
252 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
253 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
254 |
* Returns an IPv4 address as an int. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
255 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
256 |
static int inet4AsInt(InetAddress ia) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
257 |
if (ia instanceof Inet4Address) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
258 |
byte[] addr = ia.getAddress(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
259 |
int address = addr[3] & 0xFF; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
260 |
address |= ((addr[2] << 8) & 0xFF00); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
261 |
address |= ((addr[1] << 16) & 0xFF0000); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
262 |
address |= ((addr[0] << 24) & 0xFF000000); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
263 |
return address; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
264 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
265 |
throw new AssertionError("Should not reach here"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
266 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
267 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
268 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
269 |
* Returns an InetAddress from the given IPv4 address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
270 |
* represented as an int. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
271 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
272 |
static InetAddress inet4FromInt(int address) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
273 |
byte[] addr = new byte[4]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
274 |
addr[0] = (byte) ((address >>> 24) & 0xFF); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
275 |
addr[1] = (byte) ((address >>> 16) & 0xFF); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
276 |
addr[2] = (byte) ((address >>> 8) & 0xFF); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
277 |
addr[3] = (byte) (address & 0xFF); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
278 |
try { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
279 |
return InetAddress.getByAddress(addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
280 |
} catch (UnknownHostException uhe) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
281 |
throw new AssertionError("Should not reach here"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
282 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
283 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
284 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
285 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
286 |
* Returns an IPv6 address as a byte array |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
287 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
288 |
static byte[] inet6AsByteArray(InetAddress ia) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
289 |
if (ia instanceof Inet6Address) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
290 |
return ia.getAddress(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
291 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
292 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
293 |
// need to construct IPv4-mapped address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
294 |
if (ia instanceof Inet4Address) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
295 |
byte[] ip4address = ia.getAddress(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
296 |
byte[] address = new byte[16]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
297 |
address[10] = (byte)0xff; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
298 |
address[11] = (byte)0xff; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
299 |
address[12] = ip4address[0]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
300 |
address[13] = ip4address[1]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
301 |
address[14] = ip4address[2]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
302 |
address[15] = ip4address[3]; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
303 |
return address; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
304 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
305 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
306 |
throw new AssertionError("Should not reach here"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
307 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
308 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
309 |
// -- Socket options |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
310 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
311 |
static final ExtendedSocketOptions extendedOptions = |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
312 |
ExtendedSocketOptions.getInstance(); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
313 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
314 |
static void setSocketOption(FileDescriptor fd, SocketOption<?> name, Object value) |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
315 |
throws IOException |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
316 |
{ |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
317 |
setSocketOption(fd, Net.UNSPEC, name, value); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
318 |
} |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
319 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
320 |
static void setSocketOption(FileDescriptor fd, ProtocolFamily family, |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
321 |
SocketOption<?> name, Object value) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
322 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
323 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
324 |
if (value == null) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
325 |
throw new IllegalArgumentException("Invalid option value"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
326 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
327 |
// only simple values supported by this method |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
328 |
Class<?> type = name.type(); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
329 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
330 |
if (extendedOptions.isOptionSupported(name)) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
331 |
extendedOptions.setOption(fd, name, value); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
332 |
return; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
333 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
334 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
335 |
if (type != Integer.class && type != Boolean.class) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
336 |
throw new AssertionError("Should not reach here"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
337 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
338 |
// special handling |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
339 |
if (name == StandardSocketOptions.SO_RCVBUF || |
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
340 |
name == StandardSocketOptions.SO_SNDBUF) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
341 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
342 |
int i = ((Integer)value).intValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
343 |
if (i < 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
344 |
throw new IllegalArgumentException("Invalid send/receive buffer size"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
345 |
} |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
346 |
if (name == StandardSocketOptions.SO_LINGER) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
347 |
int i = ((Integer)value).intValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
348 |
if (i < 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
349 |
value = Integer.valueOf(-1); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
350 |
if (i > 65535) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
351 |
value = Integer.valueOf(65535); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
352 |
} |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
353 |
if (name == StandardSocketOptions.IP_TOS) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
354 |
int i = ((Integer)value).intValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
355 |
if (i < 0 || i > 255) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
356 |
throw new IllegalArgumentException("Invalid IP_TOS value"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
357 |
} |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
358 |
if (name == StandardSocketOptions.IP_MULTICAST_TTL) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
359 |
int i = ((Integer)value).intValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
360 |
if (i < 0 || i > 255) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
361 |
throw new IllegalArgumentException("Invalid TTL/hop value"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
362 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
363 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
364 |
// map option name to platform level/name |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
365 |
OptionKey key = SocketOptionRegistry.findOption(name, family); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
366 |
if (key == null) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
367 |
throw new AssertionError("Option not found"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
368 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
369 |
int arg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
370 |
if (type == Integer.class) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
371 |
arg = ((Integer)value).intValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
372 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
373 |
boolean b = ((Boolean)value).booleanValue(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
374 |
arg = (b) ? 1 : 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
375 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
376 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
377 |
boolean mayNeedConversion = (family == UNSPEC); |
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23879
diff
changeset
|
378 |
boolean isIPv6 = (family == StandardProtocolFamily.INET6); |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23879
diff
changeset
|
379 |
setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
380 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
381 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
382 |
static Object getSocketOption(FileDescriptor fd, SocketOption<?> name) |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
383 |
throws IOException |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
384 |
{ |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
385 |
return getSocketOption(fd, Net.UNSPEC, name); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
386 |
} |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
387 |
|
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
388 |
static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, SocketOption<?> name) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
389 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
390 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
391 |
Class<?> type = name.type(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
392 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
393 |
if (extendedOptions.isOptionSupported(name)) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
37593
diff
changeset
|
394 |
return extendedOptions.getOption(fd, name); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
395 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23010
diff
changeset
|
396 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
397 |
// only simple values supported by this method |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
398 |
if (type != Integer.class && type != Boolean.class) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
399 |
throw new AssertionError("Should not reach here"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
400 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
401 |
// map option name to platform level/name |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
402 |
OptionKey key = SocketOptionRegistry.findOption(name, family); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
403 |
if (key == null) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
404 |
throw new AssertionError("Option not found"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
405 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
406 |
boolean mayNeedConversion = (family == UNSPEC); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
407 |
int value = getIntOption0(fd, mayNeedConversion, key.level(), key.name()); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
408 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
409 |
if (type == Integer.class) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
410 |
return Integer.valueOf(value); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
411 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
412 |
return (value == 0) ? Boolean.FALSE : Boolean.TRUE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
413 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
414 |
} |
2 | 415 |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
416 |
public static boolean isFastTcpLoopbackRequested() { |
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37676
diff
changeset
|
417 |
String loopbackProp = GetPropertyAction |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
49001
diff
changeset
|
418 |
.privilegedGetProperty("jdk.net.useFastTcpLoopback", "false"); |
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
49001
diff
changeset
|
419 |
return loopbackProp.isEmpty() ? true : Boolean.parseBoolean(loopbackProp); |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
420 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
421 |
|
2 | 422 |
// -- Socket operations -- |
423 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
424 |
private static native boolean isIPv6Available0(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
425 |
|
36115 | 426 |
private static native boolean isReusePortAvailable0(); |
427 |
||
18192 | 428 |
/* |
32232 | 429 |
* Returns 1 for Windows and -1 for Solaris/Linux/Mac OS |
18192 | 430 |
*/ |
431 |
private static native int isExclusiveBindAvailable(); |
|
432 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
433 |
private static native boolean canIPv6SocketJoinIPv4Group0(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
434 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
435 |
private static native boolean canJoin6WithIPv4Group0(); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
436 |
|
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
8788
diff
changeset
|
437 |
static FileDescriptor socket(boolean stream) throws IOException { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
438 |
return socket(UNSPEC, stream); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
439 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
440 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
441 |
static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
442 |
boolean preferIPv6 = isIPv6Available() && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
443 |
(family != StandardProtocolFamily.INET); |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
444 |
return IOUtil.newFD(socket0(preferIPv6, stream, false, fastLoopback)); |
2 | 445 |
} |
446 |
||
447 |
static FileDescriptor serverSocket(boolean stream) { |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
448 |
return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback)); |
2 | 449 |
} |
450 |
||
451 |
// Due to oddities SO_REUSEADDR on windows reuse is ignored |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
452 |
private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
453 |
boolean fastLoopback); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
454 |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
9679
diff
changeset
|
455 |
public static void bind(FileDescriptor fd, InetAddress addr, int port) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
456 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
457 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
458 |
bind(UNSPEC, fd, addr, port); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
459 |
} |
2 | 460 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
461 |
static void bind(ProtocolFamily family, FileDescriptor fd, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
462 |
InetAddress addr, int port) throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
463 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
464 |
boolean preferIPv6 = isIPv6Available() && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
465 |
(family != StandardProtocolFamily.INET); |
55375 | 466 |
if (addr.isLinkLocalAddress()) { |
467 |
addr = IPAddressUtil.toScopedAddress(addr); |
|
468 |
} |
|
18192 | 469 |
bind0(fd, preferIPv6, exclusiveBind, addr, port); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
470 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
471 |
|
18192 | 472 |
private static native void bind0(FileDescriptor fd, boolean preferIPv6, |
473 |
boolean useExclBind, InetAddress addr, |
|
474 |
int port) |
|
2 | 475 |
throws IOException; |
476 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
477 |
static native void listen(FileDescriptor fd, int backlog) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
478 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
479 |
static int connect(FileDescriptor fd, InetAddress remote, int remotePort) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
480 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
481 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
482 |
return connect(UNSPEC, fd, remote, remotePort); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
483 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
484 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
485 |
static int connect(ProtocolFamily family, FileDescriptor fd, InetAddress remote, int remotePort) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
486 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
487 |
{ |
55375 | 488 |
if (remote.isLinkLocalAddress()) { |
489 |
remote = IPAddressUtil.toScopedAddress(remote); |
|
490 |
} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
491 |
boolean preferIPv6 = isIPv6Available() && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
492 |
(family != StandardProtocolFamily.INET); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
493 |
return connect0(preferIPv6, fd, remote, remotePort); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
494 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
495 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
496 |
private static native int connect0(boolean preferIPv6, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
497 |
FileDescriptor fd, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
498 |
InetAddress remote, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
499 |
int remotePort) |
2 | 500 |
throws IOException; |
501 |
||
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
502 |
public static native int accept(FileDescriptor fd, |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
503 |
FileDescriptor newfd, |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
504 |
InetSocketAddress[] isaa) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
505 |
throws IOException; |
2 | 506 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32232
diff
changeset
|
507 |
public static final int SHUT_RD = 0; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32232
diff
changeset
|
508 |
public static final int SHUT_WR = 1; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32232
diff
changeset
|
509 |
public static final int SHUT_RDWR = 2; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
510 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
511 |
static native void shutdown(FileDescriptor fd, int how) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
512 |
|
2 | 513 |
private static native int localPort(FileDescriptor fd) |
514 |
throws IOException; |
|
515 |
||
516 |
private static native InetAddress localInetAddress(FileDescriptor fd) |
|
517 |
throws IOException; |
|
518 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
9679
diff
changeset
|
519 |
public static InetSocketAddress localAddress(FileDescriptor fd) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
520 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
521 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
522 |
return new InetSocketAddress(localInetAddress(fd), localPort(fd)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
523 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
524 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
525 |
private static native int remotePort(FileDescriptor fd) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
526 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
527 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
528 |
private static native InetAddress remoteInetAddress(FileDescriptor fd) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
529 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
530 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
531 |
static InetSocketAddress remoteAddress(FileDescriptor fd) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
532 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
533 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
534 |
return new InetSocketAddress(remoteInetAddress(fd), remotePort(fd)); |
2 | 535 |
} |
536 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
537 |
private static native int getIntOption0(FileDescriptor fd, boolean mayNeedConversion, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
538 |
int level, int opt) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
539 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
540 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
541 |
private static native void setIntOption0(FileDescriptor fd, boolean mayNeedConversion, |
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23879
diff
changeset
|
542 |
int level, int opt, int arg, boolean isIPv6) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
543 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
544 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
545 |
/** |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
546 |
* Polls a file descriptor for events. |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
547 |
* @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
548 |
* @return the polled events or 0 if no events are polled |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
549 |
*/ |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
11823
diff
changeset
|
550 |
static native int poll(FileDescriptor fd, int events, long timeout) |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
11823
diff
changeset
|
551 |
throws IOException; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
11823
diff
changeset
|
552 |
|
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
553 |
/** |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
554 |
* Performs a non-blocking poll of a file descriptor. |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
555 |
* @return the polled events or 0 if no events are polled |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
556 |
*/ |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
557 |
static int pollNow(FileDescriptor fd, int events) throws IOException { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
558 |
return poll(fd, events, 0); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
559 |
} |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
560 |
|
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
561 |
/** |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
562 |
* Polls a connecting socket to test if the connection has been established. |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
563 |
* |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
564 |
* @apiNote This method is public to allow it be used by code in jdk.sctp. |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
565 |
* |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
566 |
* @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
567 |
* @return true if connected |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
568 |
*/ |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
569 |
public static native boolean pollConnect(FileDescriptor fd, long timeout) |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
570 |
throws IOException; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
571 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
572 |
/** |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
573 |
* Performs a non-blocking poll of a connecting socket to test if the |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
574 |
* connection has been established. |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
575 |
* |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
576 |
* @return true if connected |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
577 |
*/ |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
578 |
static boolean pollConnectNow(FileDescriptor fd) throws IOException { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
579 |
return pollConnect(fd, 0); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
580 |
} |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
581 |
|
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
582 |
/** |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
583 |
* Return the number of bytes in the socket input buffer. |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
584 |
*/ |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
585 |
static native int available(FileDescriptor fd) throws IOException; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
53018
diff
changeset
|
586 |
|
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
587 |
/** |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
588 |
* Send one byte of urgent data (MSG_OOB) on the socket. |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
589 |
*/ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
590 |
static native int sendOOB(FileDescriptor fd, byte data) throws IOException; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
591 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
592 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
593 |
// -- Multicast support -- |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
594 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
595 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
596 |
* Join IPv4 multicast group |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
597 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
598 |
static int join4(FileDescriptor fd, int group, int interf, int source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
599 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
600 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
601 |
return joinOrDrop4(true, fd, group, interf, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
602 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
603 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
604 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
605 |
* Drop membership of IPv4 multicast group |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
606 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
607 |
static void drop4(FileDescriptor fd, int group, int interf, int source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
608 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
609 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
610 |
joinOrDrop4(false, fd, group, interf, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
611 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
612 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
613 |
private static native int joinOrDrop4(boolean join, FileDescriptor fd, int group, int interf, int source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
614 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
615 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
616 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
617 |
* Block IPv4 source |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
618 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
619 |
static int block4(FileDescriptor fd, int group, int interf, int source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
620 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
621 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
622 |
return blockOrUnblock4(true, fd, group, interf, source); |
2 | 623 |
} |
624 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
625 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
626 |
* Unblock IPv6 source |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
627 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
628 |
static void unblock4(FileDescriptor fd, int group, int interf, int source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
629 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
630 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
631 |
blockOrUnblock4(false, fd, group, interf, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
632 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
633 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
634 |
private static native int blockOrUnblock4(boolean block, FileDescriptor fd, int group, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
635 |
int interf, int source) |
2 | 636 |
throws IOException; |
637 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
638 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
639 |
* Join IPv6 multicast group |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
640 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
641 |
static int join6(FileDescriptor fd, byte[] group, int index, byte[] source) |
2 | 642 |
throws IOException |
643 |
{ |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
644 |
return joinOrDrop6(true, fd, group, index, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
645 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
646 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
647 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
648 |
* Drop membership of IPv6 multicast group |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
649 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
650 |
static void drop6(FileDescriptor fd, byte[] group, int index, byte[] source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
651 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
652 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
653 |
joinOrDrop6(false, fd, group, index, source); |
2 | 654 |
} |
655 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
656 |
private static native int joinOrDrop6(boolean join, FileDescriptor fd, byte[] group, int index, byte[] source) |
2 | 657 |
throws IOException; |
658 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
659 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
660 |
* Block IPv6 source |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
661 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
662 |
static int block6(FileDescriptor fd, byte[] group, int index, byte[] source) |
2 | 663 |
throws IOException |
664 |
{ |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
665 |
return blockOrUnblock6(true, fd, group, index, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
666 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
667 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
668 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
669 |
* Unblock IPv6 source |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
670 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
671 |
static void unblock6(FileDescriptor fd, byte[] group, int index, byte[] source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
672 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
673 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
674 |
blockOrUnblock6(false, fd, group, index, source); |
2 | 675 |
} |
676 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
677 |
static native int blockOrUnblock6(boolean block, FileDescriptor fd, byte[] group, int index, byte[] source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
678 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
679 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
680 |
static native void setInterface4(FileDescriptor fd, int interf) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
681 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
682 |
static native int getInterface4(FileDescriptor fd) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
683 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
684 |
static native void setInterface6(FileDescriptor fd, int index) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
685 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
686 |
static native int getInterface6(FileDescriptor fd) throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
687 |
|
2 | 688 |
private static native void initIDs(); |
689 |
||
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
690 |
/** |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
691 |
* Event masks for the various poll system calls. |
47020
2c55106dc37b
8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents:
37781
diff
changeset
|
692 |
* They will be set platform dependent in the static initializer below. |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
693 |
*/ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
694 |
public static final short POLLIN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
695 |
public static final short POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
696 |
public static final short POLLERR; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
697 |
public static final short POLLHUP; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
698 |
public static final short POLLNVAL; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
699 |
public static final short POLLCONN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
700 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
701 |
static native short pollinValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
702 |
static native short polloutValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
703 |
static native short pollerrValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
704 |
static native short pollhupValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
705 |
static native short pollnvalValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
706 |
static native short pollconnValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
707 |
|
2 | 708 |
static { |
19607
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
18212
diff
changeset
|
709 |
IOUtil.load(); |
2 | 710 |
initIDs(); |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
711 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
712 |
POLLIN = pollinValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
713 |
POLLOUT = polloutValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
714 |
POLLERR = pollerrValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
715 |
POLLHUP = pollhupValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
716 |
POLLNVAL = pollnvalValue(); |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
717 |
POLLCONN = pollconnValue(); |
2 | 718 |
} |
719 |
||
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
720 |
static { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
721 |
int availLevel = isExclusiveBindAvailable(); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
722 |
if (availLevel >= 0) { |
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37676
diff
changeset
|
723 |
String exclBindProp = GetPropertyAction |
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37676
diff
changeset
|
724 |
.privilegedGetProperty("sun.net.useExclusiveBind"); |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
725 |
if (exclBindProp != null) { |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36115
diff
changeset
|
726 |
exclusiveBind = exclBindProp.isEmpty() ? |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
727 |
true : Boolean.parseBoolean(exclBindProp); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
728 |
} else if (availLevel == 1) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
729 |
exclusiveBind = true; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
730 |
} else { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
731 |
exclusiveBind = false; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
732 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
733 |
} else { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
734 |
exclusiveBind = false; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
735 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
736 |
|
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
737 |
fastLoopback = isFastTcpLoopbackRequested(); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
738 |
} |
2 | 739 |
} |