author | alanb |
Tue, 30 Apr 2019 19:34:13 +0100 | |
branch | niosocketimpl-branch |
changeset 57344 | 8b621b0d921c |
parent 57341 | 733e9746d615 |
child 57347 | 16c087c9103e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53133
bf2533105a26
8215912: Various Typos in java.net Method Documentation
coffeys
parents:
52499
diff
changeset
|
2 |
* Copyright (c) 1995, 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 java.net; |
|
27 |
||
28 |
import java.io.InputStream; |
|
29 |
import java.io.OutputStream; |
|
30 |
import java.io.IOException; |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
31 |
import java.lang.invoke.MethodHandles; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
32 |
import java.lang.invoke.VarHandle; |
2 | 33 |
import java.nio.channels.SocketChannel; |
34 |
import java.security.AccessController; |
|
35 |
import java.security.PrivilegedAction; |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
36 |
import java.util.Set; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
37 |
import java.util.Collections; |
2 | 38 |
|
39 |
/** |
|
40 |
* This class implements client sockets (also called just |
|
41 |
* "sockets"). A socket is an endpoint for communication |
|
42 |
* between two machines. |
|
43 |
* <p> |
|
44 |
* The actual work of the socket is performed by an instance of the |
|
19069 | 45 |
* {@code SocketImpl} class. An application, by changing |
2 | 46 |
* the socket factory that creates the socket implementation, |
47 |
* can configure itself to create sockets appropriate to the local |
|
48 |
* firewall. |
|
49 |
* |
|
50 |
* @author unascribed |
|
51 |
* @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) |
|
52 |
* @see java.net.SocketImpl |
|
53 |
* @see java.nio.channels.SocketChannel |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
54 |
* @since 1.0 |
2 | 55 |
*/ |
56 |
public |
|
57 |
class Socket implements java.io.Closeable { |
|
58 |
/** |
|
59 |
* Various states of this socket. |
|
60 |
*/ |
|
61 |
private boolean created = false; |
|
62 |
private boolean bound = false; |
|
63 |
private boolean connected = false; |
|
64 |
private boolean closed = false; |
|
57344 | 65 |
private Object closeLock = new Object(); |
2 | 66 |
private boolean shutIn = false; |
67 |
private boolean shutOut = false; |
|
68 |
||
69 |
/** |
|
70 |
* The implementation of this Socket. |
|
71 |
*/ |
|
72 |
SocketImpl impl; |
|
73 |
||
74 |
/** |
|
75 |
* Are we using an older SocketImpl? |
|
76 |
*/ |
|
77 |
private boolean oldImpl = false; |
|
78 |
||
79 |
/** |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
80 |
* Socket input/output streams |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
81 |
*/ |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
82 |
private volatile InputStream in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
83 |
private volatile OutputStream out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
84 |
private static final VarHandle IN, OUT; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
85 |
static { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
86 |
try { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
87 |
MethodHandles.Lookup l = MethodHandles.lookup(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
88 |
IN = l.findVarHandle(Socket.class, "in", InputStream.class); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
89 |
OUT = l.findVarHandle(Socket.class, "out", OutputStream.class); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
90 |
} catch (Exception e) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
91 |
throw new InternalError(e); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
92 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
93 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
94 |
|
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
95 |
/** |
2 | 96 |
* Creates an unconnected socket, with the |
97 |
* system-default type of SocketImpl. |
|
98 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
99 |
* @since 1.1 |
2 | 100 |
* @revised 1.4 |
101 |
*/ |
|
102 |
public Socket() { |
|
103 |
setImpl(); |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Creates an unconnected socket, specifying the type of proxy, if any, |
|
108 |
* that should be used regardless of any other settings. |
|
109 |
* <P> |
|
19069 | 110 |
* If there is a security manager, its {@code checkConnect} method |
2 | 111 |
* is called with the proxy host address and port number |
112 |
* as its arguments. This could result in a SecurityException. |
|
113 |
* <P> |
|
114 |
* Examples: |
|
19069 | 115 |
* <UL> <LI>{@code Socket s = new Socket(Proxy.NO_PROXY);} will create |
2 | 116 |
* a plain socket ignoring any other proxy configuration.</LI> |
19069 | 117 |
* <LI>{@code Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080)));} |
2 | 118 |
* will create a socket connecting through the specified SOCKS proxy |
119 |
* server.</LI> |
|
120 |
* </UL> |
|
121 |
* |
|
122 |
* @param proxy a {@link java.net.Proxy Proxy} object specifying what kind |
|
123 |
* of proxying should be used. |
|
124 |
* @throws IllegalArgumentException if the proxy is of an invalid type |
|
19069 | 125 |
* or {@code null}. |
2 | 126 |
* @throws SecurityException if a security manager is present and |
127 |
* permission to connect to the proxy is |
|
128 |
* denied. |
|
129 |
* @see java.net.ProxySelector |
|
130 |
* @see java.net.Proxy |
|
131 |
* |
|
132 |
* @since 1.5 |
|
133 |
*/ |
|
134 |
public Socket(Proxy proxy) { |
|
3442
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
135 |
// Create a copy of Proxy as a security measure |
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
136 |
if (proxy == null) { |
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
137 |
throw new IllegalArgumentException("Invalid Proxy"); |
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
138 |
} |
16061
c80133bafef0
6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
10596
diff
changeset
|
139 |
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY |
c80133bafef0
6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
10596
diff
changeset
|
140 |
: sun.net.ApplicationProxy.create(proxy); |
c80133bafef0
6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
10596
diff
changeset
|
141 |
Proxy.Type type = p.type(); |
c80133bafef0
6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
10596
diff
changeset
|
142 |
if (type == Proxy.Type.SOCKS || type == Proxy.Type.HTTP) { |
2 | 143 |
SecurityManager security = System.getSecurityManager(); |
3442
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
144 |
InetSocketAddress epoint = (InetSocketAddress) p.address(); |
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
145 |
if (epoint.getAddress() != null) { |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
146 |
checkAddress (epoint.getAddress(), "Socket"); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
147 |
} |
2 | 148 |
if (security != null) { |
149 |
if (epoint.isUnresolved()) |
|
9775 | 150 |
epoint = new InetSocketAddress(epoint.getHostName(), epoint.getPort()); |
151 |
if (epoint.isUnresolved()) |
|
152 |
security.checkConnect(epoint.getHostName(), epoint.getPort()); |
|
2 | 153 |
else |
154 |
security.checkConnect(epoint.getAddress().getHostAddress(), |
|
9775 | 155 |
epoint.getPort()); |
2 | 156 |
} |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
157 |
|
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
158 |
// create a SOCKS or HTTP SocketImpl that delegates to a platform SocketImpl |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
159 |
SocketImpl delegate = SocketImpl.createPlatformSocketImpl(false); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
160 |
impl = (type == Proxy.Type.SOCKS) ? new SocksSocketImpl(p, delegate) |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
161 |
: new HttpConnectSocketImpl(p, delegate); |
2 | 162 |
impl.setSocket(this); |
163 |
} else { |
|
3442
02df74328591
6801497: Proxy is assumed to be immutable but is non-final
jccollet
parents:
475
diff
changeset
|
164 |
if (p == Proxy.NO_PROXY) { |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
165 |
// create a platform or custom SocketImpl for the DIRECT case |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
166 |
SocketImplFactory factory = Socket.factory; |
2 | 167 |
if (factory == null) { |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
168 |
impl = SocketImpl.createPlatformSocketImpl(false); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
169 |
} else { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
170 |
impl = factory.createSocketImpl(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
171 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
172 |
impl.setSocket(this); |
2 | 173 |
} else |
174 |
throw new IllegalArgumentException("Invalid Proxy"); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Creates an unconnected Socket with a user-specified |
|
180 |
* SocketImpl. |
|
23720
7d5147c21927
8039172: Tidy warnings cleanup for java.net, java.math, java.time, java.rmi
yan
parents:
22339
diff
changeset
|
181 |
* |
2 | 182 |
* @param impl an instance of a <B>SocketImpl</B> |
183 |
* the subclass wishes to use on the Socket. |
|
184 |
* |
|
185 |
* @exception SocketException if there is an error in the underlying protocol, |
|
186 |
* such as a TCP error. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
187 |
* @since 1.1 |
2 | 188 |
*/ |
189 |
protected Socket(SocketImpl impl) throws SocketException { |
|
190 |
this.impl = impl; |
|
191 |
if (impl != null) { |
|
192 |
checkOldImpl(); |
|
193 |
this.impl.setSocket(this); |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* Creates a stream socket and connects it to the specified port |
|
199 |
* number on the named host. |
|
200 |
* <p> |
|
19069 | 201 |
* If the specified host is {@code null} it is the equivalent of |
202 |
* specifying the address as |
|
203 |
* {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}. |
|
2 | 204 |
* In other words, it is equivalent to specifying an address of the |
205 |
* loopback interface. </p> |
|
206 |
* <p> |
|
207 |
* If the application has specified a server socket factory, that |
|
19069 | 208 |
* factory's {@code createSocketImpl} method is called to create |
2 | 209 |
* the actual socket implementation. Otherwise a "plain" socket is created. |
210 |
* <p> |
|
211 |
* If there is a security manager, its |
|
19069 | 212 |
* {@code checkConnect} method is called |
213 |
* with the host address and {@code port} |
|
2 | 214 |
* as its arguments. This could result in a SecurityException. |
215 |
* |
|
19069 | 216 |
* @param host the host name, or {@code null} for the loopback address. |
2 | 217 |
* @param port the port number. |
218 |
* |
|
219 |
* @exception UnknownHostException if the IP address of |
|
220 |
* the host could not be determined. |
|
221 |
* |
|
222 |
* @exception IOException if an I/O error occurs when creating the socket. |
|
223 |
* @exception SecurityException if a security manager exists and its |
|
19069 | 224 |
* {@code checkConnect} method doesn't allow the operation. |
2 | 225 |
* @exception IllegalArgumentException if the port parameter is outside |
226 |
* the specified range of valid port values, which is between |
|
227 |
* 0 and 65535, inclusive. |
|
228 |
* @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) |
|
229 |
* @see java.net.SocketImpl |
|
230 |
* @see java.net.SocketImplFactory#createSocketImpl() |
|
231 |
* @see SecurityManager#checkConnect |
|
232 |
*/ |
|
233 |
public Socket(String host, int port) |
|
234 |
throws UnknownHostException, IOException |
|
235 |
{ |
|
236 |
this(host != null ? new InetSocketAddress(host, port) : |
|
237 |
new InetSocketAddress(InetAddress.getByName(null), port), |
|
238 |
(SocketAddress) null, true); |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* Creates a stream socket and connects it to the specified port |
|
243 |
* number at the specified IP address. |
|
244 |
* <p> |
|
245 |
* If the application has specified a socket factory, that factory's |
|
19069 | 246 |
* {@code createSocketImpl} method is called to create the |
2 | 247 |
* actual socket implementation. Otherwise a "plain" socket is created. |
248 |
* <p> |
|
249 |
* If there is a security manager, its |
|
19069 | 250 |
* {@code checkConnect} method is called |
251 |
* with the host address and {@code port} |
|
2 | 252 |
* as its arguments. This could result in a SecurityException. |
253 |
* |
|
254 |
* @param address the IP address. |
|
255 |
* @param port the port number. |
|
256 |
* @exception IOException if an I/O error occurs when creating the socket. |
|
257 |
* @exception SecurityException if a security manager exists and its |
|
19069 | 258 |
* {@code checkConnect} method doesn't allow the operation. |
2 | 259 |
* @exception IllegalArgumentException if the port parameter is outside |
260 |
* the specified range of valid port values, which is between |
|
261 |
* 0 and 65535, inclusive. |
|
19069 | 262 |
* @exception NullPointerException if {@code address} is null. |
2 | 263 |
* @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) |
264 |
* @see java.net.SocketImpl |
|
265 |
* @see java.net.SocketImplFactory#createSocketImpl() |
|
266 |
* @see SecurityManager#checkConnect |
|
267 |
*/ |
|
268 |
public Socket(InetAddress address, int port) throws IOException { |
|
269 |
this(address != null ? new InetSocketAddress(address, port) : null, |
|
270 |
(SocketAddress) null, true); |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Creates a socket and connects it to the specified remote host on |
|
275 |
* the specified remote port. The Socket will also bind() to the local |
|
276 |
* address and port supplied. |
|
277 |
* <p> |
|
19069 | 278 |
* If the specified host is {@code null} it is the equivalent of |
279 |
* specifying the address as |
|
280 |
* {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}. |
|
2 | 281 |
* In other words, it is equivalent to specifying an address of the |
282 |
* loopback interface. </p> |
|
283 |
* <p> |
|
19069 | 284 |
* A local port number of {@code zero} will let the system pick up a |
285 |
* free port in the {@code bind} operation.</p> |
|
2 | 286 |
* <p> |
287 |
* If there is a security manager, its |
|
19069 | 288 |
* {@code checkConnect} method is called |
289 |
* with the host address and {@code port} |
|
2 | 290 |
* as its arguments. This could result in a SecurityException. |
291 |
* |
|
19069 | 292 |
* @param host the name of the remote host, or {@code null} for the loopback address. |
2 | 293 |
* @param port the remote port |
475
b8b79ef97ac8
6571950: SSLSocket(raddr, rport, laddr, lport) allows null as laddr that spec doesn't reflect
xuelei
parents:
94
diff
changeset
|
294 |
* @param localAddr the local address the socket is bound to, or |
19069 | 295 |
* {@code null} for the {@code anyLocal} address. |
2 | 296 |
* @param localPort the local port the socket is bound to, or |
19069 | 297 |
* {@code zero} for a system selected free port. |
2 | 298 |
* @exception IOException if an I/O error occurs when creating the socket. |
299 |
* @exception SecurityException if a security manager exists and its |
|
22339 | 300 |
* {@code checkConnect} method doesn't allow the connection |
301 |
* to the destination, or if its {@code checkListen} method |
|
302 |
* doesn't allow the bind to the local port. |
|
2 | 303 |
* @exception IllegalArgumentException if the port parameter or localPort |
304 |
* parameter is outside the specified range of valid port values, |
|
305 |
* which is between 0 and 65535, inclusive. |
|
306 |
* @see SecurityManager#checkConnect |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
307 |
* @since 1.1 |
2 | 308 |
*/ |
309 |
public Socket(String host, int port, InetAddress localAddr, |
|
310 |
int localPort) throws IOException { |
|
311 |
this(host != null ? new InetSocketAddress(host, port) : |
|
312 |
new InetSocketAddress(InetAddress.getByName(null), port), |
|
313 |
new InetSocketAddress(localAddr, localPort), true); |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Creates a socket and connects it to the specified remote address on |
|
318 |
* the specified remote port. The Socket will also bind() to the local |
|
319 |
* address and port supplied. |
|
320 |
* <p> |
|
19069 | 321 |
* If the specified local address is {@code null} it is the equivalent of |
322 |
* specifying the address as the AnyLocal address |
|
323 |
* (see {@link java.net.InetAddress#isAnyLocalAddress InetAddress.isAnyLocalAddress}{@code ()}). |
|
2 | 324 |
* <p> |
19069 | 325 |
* A local port number of {@code zero} will let the system pick up a |
326 |
* free port in the {@code bind} operation.</p> |
|
2 | 327 |
* <p> |
328 |
* If there is a security manager, its |
|
19069 | 329 |
* {@code checkConnect} method is called |
330 |
* with the host address and {@code port} |
|
2 | 331 |
* as its arguments. This could result in a SecurityException. |
332 |
* |
|
333 |
* @param address the remote address |
|
334 |
* @param port the remote port |
|
335 |
* @param localAddr the local address the socket is bound to, or |
|
19069 | 336 |
* {@code null} for the {@code anyLocal} address. |
2 | 337 |
* @param localPort the local port the socket is bound to or |
19069 | 338 |
* {@code zero} for a system selected free port. |
2 | 339 |
* @exception IOException if an I/O error occurs when creating the socket. |
340 |
* @exception SecurityException if a security manager exists and its |
|
22339 | 341 |
* {@code checkConnect} method doesn't allow the connection |
342 |
* to the destination, or if its {@code checkListen} method |
|
343 |
* doesn't allow the bind to the local port. |
|
2 | 344 |
* @exception IllegalArgumentException if the port parameter or localPort |
345 |
* parameter is outside the specified range of valid port values, |
|
346 |
* which is between 0 and 65535, inclusive. |
|
19069 | 347 |
* @exception NullPointerException if {@code address} is null. |
2 | 348 |
* @see SecurityManager#checkConnect |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
349 |
* @since 1.1 |
2 | 350 |
*/ |
351 |
public Socket(InetAddress address, int port, InetAddress localAddr, |
|
352 |
int localPort) throws IOException { |
|
353 |
this(address != null ? new InetSocketAddress(address, port) : null, |
|
354 |
new InetSocketAddress(localAddr, localPort), true); |
|
355 |
} |
|
356 |
||
357 |
/** |
|
358 |
* Creates a stream socket and connects it to the specified port |
|
359 |
* number on the named host. |
|
360 |
* <p> |
|
19069 | 361 |
* If the specified host is {@code null} it is the equivalent of |
362 |
* specifying the address as |
|
363 |
* {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}. |
|
2 | 364 |
* In other words, it is equivalent to specifying an address of the |
365 |
* loopback interface. </p> |
|
366 |
* <p> |
|
19069 | 367 |
* If the stream argument is {@code true}, this creates a |
368 |
* stream socket. If the stream argument is {@code false}, it |
|
2 | 369 |
* creates a datagram socket. |
370 |
* <p> |
|
371 |
* If the application has specified a server socket factory, that |
|
19069 | 372 |
* factory's {@code createSocketImpl} method is called to create |
2 | 373 |
* the actual socket implementation. Otherwise a "plain" socket is created. |
374 |
* <p> |
|
375 |
* If there is a security manager, its |
|
19069 | 376 |
* {@code checkConnect} method is called |
377 |
* with the host address and {@code port} |
|
2 | 378 |
* as its arguments. This could result in a SecurityException. |
379 |
* <p> |
|
380 |
* If a UDP socket is used, TCP/IP related socket options will not apply. |
|
381 |
* |
|
19069 | 382 |
* @param host the host name, or {@code null} for the loopback address. |
2 | 383 |
* @param port the port number. |
19069 | 384 |
* @param stream a {@code boolean} indicating whether this is |
2 | 385 |
* a stream socket or a datagram socket. |
386 |
* @exception IOException if an I/O error occurs when creating the socket. |
|
387 |
* @exception SecurityException if a security manager exists and its |
|
19069 | 388 |
* {@code checkConnect} method doesn't allow the operation. |
2 | 389 |
* @exception IllegalArgumentException if the port parameter is outside |
390 |
* the specified range of valid port values, which is between |
|
391 |
* 0 and 65535, inclusive. |
|
392 |
* @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) |
|
393 |
* @see java.net.SocketImpl |
|
394 |
* @see java.net.SocketImplFactory#createSocketImpl() |
|
395 |
* @see SecurityManager#checkConnect |
|
396 |
* @deprecated Use DatagramSocket instead for UDP transport. |
|
397 |
*/ |
|
398 |
@Deprecated |
|
399 |
public Socket(String host, int port, boolean stream) throws IOException { |
|
400 |
this(host != null ? new InetSocketAddress(host, port) : |
|
401 |
new InetSocketAddress(InetAddress.getByName(null), port), |
|
402 |
(SocketAddress) null, stream); |
|
403 |
} |
|
404 |
||
405 |
/** |
|
406 |
* Creates a socket and connects it to the specified port number at |
|
407 |
* the specified IP address. |
|
408 |
* <p> |
|
19069 | 409 |
* If the stream argument is {@code true}, this creates a |
410 |
* stream socket. If the stream argument is {@code false}, it |
|
2 | 411 |
* creates a datagram socket. |
412 |
* <p> |
|
413 |
* If the application has specified a server socket factory, that |
|
19069 | 414 |
* factory's {@code createSocketImpl} method is called to create |
2 | 415 |
* the actual socket implementation. Otherwise a "plain" socket is created. |
416 |
* |
|
417 |
* <p>If there is a security manager, its |
|
19069 | 418 |
* {@code checkConnect} method is called |
419 |
* with {@code host.getHostAddress()} and {@code port} |
|
2 | 420 |
* as its arguments. This could result in a SecurityException. |
421 |
* <p> |
|
422 |
* If UDP socket is used, TCP/IP related socket options will not apply. |
|
423 |
* |
|
424 |
* @param host the IP address. |
|
425 |
* @param port the port number. |
|
19069 | 426 |
* @param stream if {@code true}, create a stream socket; |
2 | 427 |
* otherwise, create a datagram socket. |
428 |
* @exception IOException if an I/O error occurs when creating the socket. |
|
429 |
* @exception SecurityException if a security manager exists and its |
|
19069 | 430 |
* {@code checkConnect} method doesn't allow the operation. |
2 | 431 |
* @exception IllegalArgumentException if the port parameter is outside |
432 |
* the specified range of valid port values, which is between |
|
433 |
* 0 and 65535, inclusive. |
|
19069 | 434 |
* @exception NullPointerException if {@code host} is null. |
2 | 435 |
* @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) |
436 |
* @see java.net.SocketImpl |
|
437 |
* @see java.net.SocketImplFactory#createSocketImpl() |
|
438 |
* @see SecurityManager#checkConnect |
|
439 |
* @deprecated Use DatagramSocket instead for UDP transport. |
|
440 |
*/ |
|
441 |
@Deprecated |
|
442 |
public Socket(InetAddress host, int port, boolean stream) throws IOException { |
|
443 |
this(host != null ? new InetSocketAddress(host, port) : null, |
|
444 |
new InetSocketAddress(0), stream); |
|
445 |
} |
|
446 |
||
447 |
private Socket(SocketAddress address, SocketAddress localAddr, |
|
448 |
boolean stream) throws IOException { |
|
449 |
setImpl(); |
|
450 |
||
451 |
// backward compatibility |
|
452 |
if (address == null) |
|
453 |
throw new NullPointerException(); |
|
454 |
||
455 |
try { |
|
456 |
createImpl(stream); |
|
457 |
if (localAddr != null) |
|
458 |
bind(localAddr); |
|
10439 | 459 |
connect(address); |
460 |
} catch (IOException | IllegalArgumentException | SecurityException e) { |
|
461 |
try { |
|
462 |
close(); |
|
463 |
} catch (IOException ce) { |
|
464 |
e.addSuppressed(ce); |
|
465 |
} |
|
2 | 466 |
throw e; |
467 |
} |
|
468 |
} |
|
469 |
||
470 |
/** |
|
471 |
* Creates the socket implementation. |
|
472 |
* |
|
19069 | 473 |
* @param stream a {@code boolean} value : {@code true} for a TCP socket, |
474 |
* {@code false} for UDP. |
|
2 | 475 |
* @throws IOException if creation fails |
476 |
* @since 1.4 |
|
477 |
*/ |
|
478 |
void createImpl(boolean stream) throws SocketException { |
|
479 |
if (impl == null) |
|
480 |
setImpl(); |
|
481 |
try { |
|
482 |
impl.create(stream); |
|
483 |
created = true; |
|
484 |
} catch (IOException e) { |
|
485 |
throw new SocketException(e.getMessage()); |
|
486 |
} |
|
487 |
} |
|
488 |
||
489 |
private void checkOldImpl() { |
|
490 |
if (impl == null) |
|
491 |
return; |
|
492 |
// SocketImpl.connect() is a protected method, therefore we need to use |
|
493 |
// getDeclaredMethod, therefore we need permission to access the member |
|
494 |
||
495 |
oldImpl = AccessController.doPrivileged |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
28852
diff
changeset
|
496 |
(new PrivilegedAction<>() { |
2 | 497 |
public Boolean run() { |
10596
39b3a979e600
7090158: Networking Libraries don't build with javac -Werror
chegar
parents:
10439
diff
changeset
|
498 |
Class<?> clazz = impl.getClass(); |
2 | 499 |
while (true) { |
500 |
try { |
|
10596
39b3a979e600
7090158: Networking Libraries don't build with javac -Werror
chegar
parents:
10439
diff
changeset
|
501 |
clazz.getDeclaredMethod("connect", SocketAddress.class, int.class); |
2 | 502 |
return Boolean.FALSE; |
503 |
} catch (NoSuchMethodException e) { |
|
504 |
clazz = clazz.getSuperclass(); |
|
505 |
// java.net.SocketImpl class will always have this abstract method. |
|
506 |
// If we have not found it by now in the hierarchy then it does not |
|
507 |
// exist, we are an old style impl. |
|
508 |
if (clazz.equals(java.net.SocketImpl.class)) { |
|
509 |
return Boolean.TRUE; |
|
510 |
} |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
}); |
|
515 |
} |
|
516 |
||
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
517 |
void setImpl(SocketImpl si) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
518 |
impl = si; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
519 |
impl.setSocket(this); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
520 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
521 |
|
2 | 522 |
/** |
523 |
* Sets impl to the system-default type of SocketImpl. |
|
524 |
* @since 1.4 |
|
525 |
*/ |
|
526 |
void setImpl() { |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
527 |
SocketImplFactory factory = Socket.factory; |
2 | 528 |
if (factory != null) { |
529 |
impl = factory.createSocketImpl(); |
|
530 |
checkOldImpl(); |
|
531 |
} else { |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
532 |
// create a SOCKS SocketImpl that delegates to a platform SocketImpl |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
533 |
SocketImpl delegate = SocketImpl.createPlatformSocketImpl(false); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
534 |
impl = new SocksSocketImpl(delegate); |
2 | 535 |
} |
536 |
if (impl != null) |
|
537 |
impl.setSocket(this); |
|
538 |
} |
|
539 |
||
540 |
/** |
|
19069 | 541 |
* Get the {@code SocketImpl} attached to this socket, creating |
2 | 542 |
* it if necessary. |
543 |
* |
|
19069 | 544 |
* @return the {@code SocketImpl} attached to that ServerSocket. |
2 | 545 |
* @throws SocketException if creation fails |
546 |
* @since 1.4 |
|
547 |
*/ |
|
548 |
SocketImpl getImpl() throws SocketException { |
|
549 |
if (!created) |
|
550 |
createImpl(true); |
|
551 |
return impl; |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* Connects this socket to the server. |
|
556 |
* |
|
19069 | 557 |
* @param endpoint the {@code SocketAddress} |
2 | 558 |
* @throws IOException if an error occurs during the connection |
559 |
* @throws java.nio.channels.IllegalBlockingModeException |
|
560 |
* if this socket has an associated channel, |
|
561 |
* and the channel is in non-blocking mode |
|
562 |
* @throws IllegalArgumentException if endpoint is null or is a |
|
563 |
* SocketAddress subclass not supported by this socket |
|
564 |
* @since 1.4 |
|
565 |
* @spec JSR-51 |
|
566 |
*/ |
|
567 |
public void connect(SocketAddress endpoint) throws IOException { |
|
568 |
connect(endpoint, 0); |
|
569 |
} |
|
570 |
||
571 |
/** |
|
572 |
* Connects this socket to the server with a specified timeout value. |
|
573 |
* A timeout of zero is interpreted as an infinite timeout. The connection |
|
574 |
* will then block until established or an error occurs. |
|
575 |
* |
|
19069 | 576 |
* @param endpoint the {@code SocketAddress} |
2 | 577 |
* @param timeout the timeout value to be used in milliseconds. |
578 |
* @throws IOException if an error occurs during the connection |
|
579 |
* @throws SocketTimeoutException if timeout expires before connecting |
|
580 |
* @throws java.nio.channels.IllegalBlockingModeException |
|
581 |
* if this socket has an associated channel, |
|
582 |
* and the channel is in non-blocking mode |
|
583 |
* @throws IllegalArgumentException if endpoint is null or is a |
|
54289
6183f835b9b6
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
chegar
parents:
54155
diff
changeset
|
584 |
* SocketAddress subclass not supported by this socket, or |
6183f835b9b6
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
chegar
parents:
54155
diff
changeset
|
585 |
* if {@code timeout} is negative |
2 | 586 |
* @since 1.4 |
587 |
* @spec JSR-51 |
|
588 |
*/ |
|
589 |
public void connect(SocketAddress endpoint, int timeout) throws IOException { |
|
590 |
if (endpoint == null) |
|
591 |
throw new IllegalArgumentException("connect: The address can't be null"); |
|
592 |
||
593 |
if (timeout < 0) |
|
594 |
throw new IllegalArgumentException("connect: timeout can't be negative"); |
|
595 |
||
596 |
if (isClosed()) |
|
597 |
throw new SocketException("Socket is closed"); |
|
598 |
||
599 |
if (!oldImpl && isConnected()) |
|
600 |
throw new SocketException("already connected"); |
|
601 |
||
602 |
if (!(endpoint instanceof InetSocketAddress)) |
|
603 |
throw new IllegalArgumentException("Unsupported address type"); |
|
604 |
||
605 |
InetSocketAddress epoint = (InetSocketAddress) endpoint; |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
606 |
InetAddress addr = epoint.getAddress (); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
607 |
int port = epoint.getPort(); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
608 |
checkAddress(addr, "connect"); |
2 | 609 |
|
610 |
SecurityManager security = System.getSecurityManager(); |
|
611 |
if (security != null) { |
|
612 |
if (epoint.isUnresolved()) |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
613 |
security.checkConnect(epoint.getHostName(), port); |
2 | 614 |
else |
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
615 |
security.checkConnect(addr.getHostAddress(), port); |
2 | 616 |
} |
617 |
if (!created) |
|
618 |
createImpl(true); |
|
619 |
if (!oldImpl) |
|
620 |
impl.connect(epoint, timeout); |
|
621 |
else if (timeout == 0) { |
|
622 |
if (epoint.isUnresolved()) |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
623 |
impl.connect(addr.getHostName(), port); |
2 | 624 |
else |
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
625 |
impl.connect(addr, port); |
2 | 626 |
} else |
627 |
throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)"); |
|
628 |
connected = true; |
|
629 |
/* |
|
630 |
* If the socket was not bound before the connect, it is now because |
|
631 |
* the kernel will have picked an ephemeral port & a local address |
|
632 |
*/ |
|
633 |
bound = true; |
|
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
* Binds the socket to a local address. |
|
638 |
* <P> |
|
19069 | 639 |
* If the address is {@code null}, then the system will pick up |
2 | 640 |
* an ephemeral port and a valid local address to bind the socket. |
641 |
* |
|
19069 | 642 |
* @param bindpoint the {@code SocketAddress} to bind to |
2 | 643 |
* @throws IOException if the bind operation fails, or if the socket |
644 |
* is already bound. |
|
645 |
* @throws IllegalArgumentException if bindpoint is a |
|
646 |
* SocketAddress subclass not supported by this socket |
|
22339 | 647 |
* @throws SecurityException if a security manager exists and its |
648 |
* {@code checkListen} method doesn't allow the bind |
|
649 |
* to the local port. |
|
2 | 650 |
* |
651 |
* @since 1.4 |
|
652 |
* @see #isBound |
|
653 |
*/ |
|
654 |
public void bind(SocketAddress bindpoint) throws IOException { |
|
655 |
if (isClosed()) |
|
656 |
throw new SocketException("Socket is closed"); |
|
657 |
if (!oldImpl && isBound()) |
|
658 |
throw new SocketException("Already bound"); |
|
659 |
||
660 |
if (bindpoint != null && (!(bindpoint instanceof InetSocketAddress))) |
|
661 |
throw new IllegalArgumentException("Unsupported address type"); |
|
662 |
InetSocketAddress epoint = (InetSocketAddress) bindpoint; |
|
663 |
if (epoint != null && epoint.isUnresolved()) |
|
664 |
throw new SocketException("Unresolved address"); |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
665 |
if (epoint == null) { |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
666 |
epoint = new InetSocketAddress(0); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
667 |
} |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
668 |
InetAddress addr = epoint.getAddress(); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
669 |
int port = epoint.getPort(); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
670 |
checkAddress (addr, "bind"); |
22339 | 671 |
SecurityManager security = System.getSecurityManager(); |
672 |
if (security != null) { |
|
673 |
security.checkListen(port); |
|
674 |
} |
|
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
675 |
getImpl().bind (addr, port); |
2 | 676 |
bound = true; |
677 |
} |
|
678 |
||
5180
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
679 |
private void checkAddress (InetAddress addr, String op) { |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
680 |
if (addr == null) { |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
681 |
return; |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
682 |
} |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
683 |
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) { |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
684 |
throw new IllegalArgumentException(op + ": invalid address type"); |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
685 |
} |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
686 |
} |
8161f879d704
6893954: Subclasses of InetAddress may incorrectly interpret network addresses
michaelm
parents:
3450
diff
changeset
|
687 |
|
2 | 688 |
/** |
689 |
* set the flags after an accept() call. |
|
690 |
*/ |
|
691 |
final void postAccept() { |
|
692 |
connected = true; |
|
693 |
created = true; |
|
694 |
bound = true; |
|
695 |
} |
|
696 |
||
697 |
void setCreated() { |
|
698 |
created = true; |
|
699 |
} |
|
700 |
||
701 |
void setBound() { |
|
702 |
bound = true; |
|
703 |
} |
|
704 |
||
705 |
void setConnected() { |
|
706 |
connected = true; |
|
707 |
} |
|
708 |
||
709 |
/** |
|
710 |
* Returns the address to which the socket is connected. |
|
711 |
* <p> |
|
712 |
* If the socket was connected prior to being {@link #close closed}, |
|
713 |
* then this method will continue to return the connected address |
|
714 |
* after the socket is closed. |
|
715 |
* |
|
716 |
* @return the remote IP address to which this socket is connected, |
|
19069 | 717 |
* or {@code null} if the socket is not connected. |
2 | 718 |
*/ |
719 |
public InetAddress getInetAddress() { |
|
720 |
if (!isConnected()) |
|
721 |
return null; |
|
722 |
try { |
|
723 |
return getImpl().getInetAddress(); |
|
724 |
} catch (SocketException e) { |
|
725 |
} |
|
726 |
return null; |
|
727 |
} |
|
728 |
||
729 |
/** |
|
730 |
* Gets the local address to which the socket is bound. |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
731 |
* <p> |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
732 |
* If there is a security manager set, its {@code checkConnect} method is |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
733 |
* called with the local address and {@code -1} as its arguments to see |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
734 |
* if the operation is allowed. If the operation is not allowed, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
735 |
* the {@link InetAddress#getLoopbackAddress loopback} address is returned. |
2 | 736 |
* |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
737 |
* @return the local address to which the socket is bound, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
738 |
* the loopback address if denied by the security manager, or |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
739 |
* the wildcard address if the socket is closed or not bound yet. |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
740 |
* @since 1.1 |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
741 |
* |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
742 |
* @see SecurityManager#checkConnect |
2 | 743 |
*/ |
744 |
public InetAddress getLocalAddress() { |
|
745 |
// This is for backward compatibility |
|
746 |
if (!isBound()) |
|
747 |
return InetAddress.anyLocalAddress(); |
|
748 |
InetAddress in = null; |
|
749 |
try { |
|
750 |
in = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
751 |
SecurityManager sm = System.getSecurityManager(); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
752 |
if (sm != null) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
753 |
sm.checkConnect(in.getHostAddress(), -1); |
2 | 754 |
if (in.isAnyLocalAddress()) { |
755 |
in = InetAddress.anyLocalAddress(); |
|
756 |
} |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
757 |
} catch (SecurityException e) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
758 |
in = InetAddress.getLoopbackAddress(); |
2 | 759 |
} catch (Exception e) { |
760 |
in = InetAddress.anyLocalAddress(); // "0.0.0.0" |
|
761 |
} |
|
762 |
return in; |
|
763 |
} |
|
764 |
||
765 |
/** |
|
766 |
* Returns the remote port number to which this socket is connected. |
|
767 |
* <p> |
|
768 |
* If the socket was connected prior to being {@link #close closed}, |
|
769 |
* then this method will continue to return the connected port number |
|
770 |
* after the socket is closed. |
|
771 |
* |
|
772 |
* @return the remote port number to which this socket is connected, or |
|
773 |
* 0 if the socket is not connected yet. |
|
774 |
*/ |
|
775 |
public int getPort() { |
|
776 |
if (!isConnected()) |
|
777 |
return 0; |
|
778 |
try { |
|
779 |
return getImpl().getPort(); |
|
780 |
} catch (SocketException e) { |
|
781 |
// Shouldn't happen as we're connected |
|
782 |
} |
|
783 |
return -1; |
|
784 |
} |
|
785 |
||
786 |
/** |
|
787 |
* Returns the local port number to which this socket is bound. |
|
788 |
* <p> |
|
789 |
* If the socket was bound prior to being {@link #close closed}, |
|
790 |
* then this method will continue to return the local port number |
|
791 |
* after the socket is closed. |
|
792 |
* |
|
793 |
* @return the local port number to which this socket is bound or -1 |
|
794 |
* if the socket is not bound yet. |
|
795 |
*/ |
|
796 |
public int getLocalPort() { |
|
797 |
if (!isBound()) |
|
798 |
return -1; |
|
799 |
try { |
|
800 |
return getImpl().getLocalPort(); |
|
801 |
} catch(SocketException e) { |
|
802 |
// shouldn't happen as we're bound |
|
803 |
} |
|
804 |
return -1; |
|
805 |
} |
|
806 |
||
807 |
/** |
|
808 |
* Returns the address of the endpoint this socket is connected to, or |
|
19069 | 809 |
* {@code null} if it is unconnected. |
2 | 810 |
* <p> |
811 |
* If the socket was connected prior to being {@link #close closed}, |
|
812 |
* then this method will continue to return the connected address |
|
813 |
* after the socket is closed. |
|
814 |
* |
|
94 | 815 |
|
19069 | 816 |
* @return a {@code SocketAddress} representing the remote endpoint of this |
817 |
* socket, or {@code null} if it is not connected yet. |
|
2 | 818 |
* @see #getInetAddress() |
819 |
* @see #getPort() |
|
820 |
* @see #connect(SocketAddress, int) |
|
821 |
* @see #connect(SocketAddress) |
|
822 |
* @since 1.4 |
|
823 |
*/ |
|
824 |
public SocketAddress getRemoteSocketAddress() { |
|
825 |
if (!isConnected()) |
|
826 |
return null; |
|
827 |
return new InetSocketAddress(getInetAddress(), getPort()); |
|
828 |
} |
|
829 |
||
830 |
/** |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
831 |
* Returns the address of the endpoint this socket is bound to. |
2 | 832 |
* <p> |
833 |
* If a socket bound to an endpoint represented by an |
|
19069 | 834 |
* {@code InetSocketAddress } is {@link #close closed}, |
835 |
* then this method will continue to return an {@code InetSocketAddress} |
|
2 | 836 |
* after the socket is closed. In that case the returned |
19069 | 837 |
* {@code InetSocketAddress}'s address is the |
2 | 838 |
* {@link InetAddress#isAnyLocalAddress wildcard} address |
839 |
* and its port is the local port that it was bound to. |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
840 |
* <p> |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
841 |
* If there is a security manager set, its {@code checkConnect} method is |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
842 |
* called with the local address and {@code -1} as its arguments to see |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
843 |
* if the operation is allowed. If the operation is not allowed, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
844 |
* a {@code SocketAddress} representing the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
845 |
* {@link InetAddress#getLoopbackAddress loopback} address and the local |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
846 |
* port to which this socket is bound is returned. |
2 | 847 |
* |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
848 |
* @return a {@code SocketAddress} representing the local endpoint of |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
849 |
* this socket, or a {@code SocketAddress} representing the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
850 |
* loopback address if denied by the security manager, or |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
851 |
* {@code null} if the socket is not bound yet. |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
852 |
* |
2 | 853 |
* @see #getLocalAddress() |
854 |
* @see #getLocalPort() |
|
855 |
* @see #bind(SocketAddress) |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
16061
diff
changeset
|
856 |
* @see SecurityManager#checkConnect |
2 | 857 |
* @since 1.4 |
858 |
*/ |
|
859 |
||
860 |
public SocketAddress getLocalSocketAddress() { |
|
861 |
if (!isBound()) |
|
862 |
return null; |
|
863 |
return new InetSocketAddress(getLocalAddress(), getLocalPort()); |
|
864 |
} |
|
865 |
||
866 |
/** |
|
867 |
* Returns the unique {@link java.nio.channels.SocketChannel SocketChannel} |
|
868 |
* object associated with this socket, if any. |
|
869 |
* |
|
870 |
* <p> A socket will have a channel if, and only if, the channel itself was |
|
871 |
* created via the {@link java.nio.channels.SocketChannel#open |
|
872 |
* SocketChannel.open} or {@link |
|
873 |
* java.nio.channels.ServerSocketChannel#accept ServerSocketChannel.accept} |
|
874 |
* methods. |
|
875 |
* |
|
876 |
* @return the socket channel associated with this socket, |
|
19069 | 877 |
* or {@code null} if this socket was not created |
2 | 878 |
* for a channel |
879 |
* |
|
880 |
* @since 1.4 |
|
881 |
* @spec JSR-51 |
|
882 |
*/ |
|
883 |
public SocketChannel getChannel() { |
|
884 |
return null; |
|
885 |
} |
|
886 |
||
887 |
/** |
|
888 |
* Returns an input stream for this socket. |
|
889 |
* |
|
890 |
* <p> If this socket has an associated channel then the resulting input |
|
891 |
* stream delegates all of its operations to the channel. If the channel |
|
19069 | 892 |
* is in non-blocking mode then the input stream's {@code read} operations |
2 | 893 |
* will throw an {@link java.nio.channels.IllegalBlockingModeException}. |
894 |
* |
|
895 |
* <p>Under abnormal conditions the underlying connection may be |
|
896 |
* broken by the remote host or the network software (for example |
|
897 |
* a connection reset in the case of TCP connections). When a |
|
898 |
* broken connection is detected by the network software the |
|
899 |
* following applies to the returned input stream :- |
|
900 |
* |
|
901 |
* <ul> |
|
902 |
* |
|
903 |
* <li><p>The network software may discard bytes that are buffered |
|
904 |
* by the socket. Bytes that aren't discarded by the network |
|
905 |
* software can be read using {@link java.io.InputStream#read read}. |
|
906 |
* |
|
907 |
* <li><p>If there are no bytes buffered on the socket, or all |
|
908 |
* buffered bytes have been consumed by |
|
909 |
* {@link java.io.InputStream#read read}, then all subsequent |
|
910 |
* calls to {@link java.io.InputStream#read read} will throw an |
|
911 |
* {@link java.io.IOException IOException}. |
|
912 |
* |
|
913 |
* <li><p>If there are no bytes buffered on the socket, and the |
|
914 |
* socket has not been closed using {@link #close close}, then |
|
915 |
* {@link java.io.InputStream#available available} will |
|
19069 | 916 |
* return {@code 0}. |
2 | 917 |
* |
918 |
* </ul> |
|
919 |
* |
|
920 |
* <p> Closing the returned {@link java.io.InputStream InputStream} |
|
921 |
* will close the associated socket. |
|
922 |
* |
|
923 |
* @return an input stream for reading bytes from this socket. |
|
924 |
* @exception IOException if an I/O error occurs when creating the |
|
925 |
* input stream, the socket is closed, the socket is |
|
926 |
* not connected, or the socket input has been shutdown |
|
927 |
* using {@link #shutdownInput()} |
|
928 |
* |
|
929 |
* @revised 1.4 |
|
930 |
* @spec JSR-51 |
|
931 |
*/ |
|
932 |
public InputStream getInputStream() throws IOException { |
|
933 |
if (isClosed()) |
|
934 |
throw new SocketException("Socket is closed"); |
|
935 |
if (!isConnected()) |
|
936 |
throw new SocketException("Socket is not connected"); |
|
937 |
if (isInputShutdown()) |
|
938 |
throw new SocketException("Socket input is shutdown"); |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
939 |
InputStream in = this.in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
940 |
if (in == null) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
941 |
// wrap the input stream so that the close method closes this socket |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
942 |
in = new SocketInputStream(this, impl.getInputStream()); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
943 |
if (!IN.compareAndSet(this, null, in)) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
944 |
in = this.in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
945 |
} |
2 | 946 |
} |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
947 |
return in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
948 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
949 |
|
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
950 |
/** |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
951 |
* An InputStream that delegates read/available operations to an underlying |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
952 |
* input stream. The close method is overridden to close the Socket. |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
953 |
* |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
954 |
* This class is instrumented by Java Flight Recorder (JFR) to get socket |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
955 |
* I/O events. |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
956 |
*/ |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
957 |
private static class SocketInputStream extends InputStream { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
958 |
private final Socket parent; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
959 |
private final InputStream in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
960 |
SocketInputStream(Socket parent, InputStream in) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
961 |
this.parent = parent; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
962 |
this.in = in; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
963 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
964 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
965 |
public int read() throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
966 |
byte[] a = new byte[1]; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
967 |
int n = read(a, 0, 1); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
968 |
return (n > 0) ? (a[0] & 0xff) : -1; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
969 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
970 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
971 |
public int read(byte b[], int off, int len) throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
972 |
return in.read(b, off, len); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
973 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
974 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
975 |
public int available() throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
976 |
return in.available(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
977 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
978 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
979 |
public void close() throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
980 |
parent.close(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
981 |
} |
2 | 982 |
} |
983 |
||
984 |
/** |
|
985 |
* Returns an output stream for this socket. |
|
986 |
* |
|
987 |
* <p> If this socket has an associated channel then the resulting output |
|
988 |
* stream delegates all of its operations to the channel. If the channel |
|
19069 | 989 |
* is in non-blocking mode then the output stream's {@code write} |
2 | 990 |
* operations will throw an {@link |
991 |
* java.nio.channels.IllegalBlockingModeException}. |
|
992 |
* |
|
993 |
* <p> Closing the returned {@link java.io.OutputStream OutputStream} |
|
994 |
* will close the associated socket. |
|
995 |
* |
|
996 |
* @return an output stream for writing bytes to this socket. |
|
997 |
* @exception IOException if an I/O error occurs when creating the |
|
998 |
* output stream or if the socket is not connected. |
|
999 |
* @revised 1.4 |
|
1000 |
* @spec JSR-51 |
|
1001 |
*/ |
|
1002 |
public OutputStream getOutputStream() throws IOException { |
|
1003 |
if (isClosed()) |
|
1004 |
throw new SocketException("Socket is closed"); |
|
1005 |
if (!isConnected()) |
|
1006 |
throw new SocketException("Socket is not connected"); |
|
1007 |
if (isOutputShutdown()) |
|
1008 |
throw new SocketException("Socket output is shutdown"); |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1009 |
OutputStream out = this.out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1010 |
if (out == null) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1011 |
// wrap the output stream so that the close method closes this socket |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1012 |
out = new SocketOutputStream(this, impl.getOutputStream()); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1013 |
if (!OUT.compareAndSet(this, null, out)) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1014 |
out = this.out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1015 |
} |
2 | 1016 |
} |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1017 |
return out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1018 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1019 |
|
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1020 |
/** |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1021 |
* An OutputStream that delegates write operations to an underlying output |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1022 |
* stream. The close method is overridden to close the Socket. |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1023 |
* |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1024 |
* This class is instrumented by Java Flight Recorder (JFR) to get socket |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1025 |
* I/O events. |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1026 |
*/ |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1027 |
private static class SocketOutputStream extends OutputStream { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1028 |
private final Socket parent; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1029 |
private final OutputStream out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1030 |
SocketOutputStream(Socket parent, OutputStream out) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1031 |
this.parent = parent; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1032 |
this.out = out; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1033 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1034 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1035 |
public void write(int b) throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1036 |
byte[] a = new byte[] { (byte) b }; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1037 |
write(a, 0, 1); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1038 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1039 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1040 |
public void write(byte b[], int off, int len) throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1041 |
out.write(b, off, len); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1042 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1043 |
@Override |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1044 |
public void close() throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1045 |
parent.close(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1046 |
} |
2 | 1047 |
} |
1048 |
||
1049 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1050 |
* Enable/disable {@link SocketOptions#TCP_NODELAY TCP_NODELAY} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1051 |
* (disable/enable Nagle's algorithm). |
2 | 1052 |
* |
19069 | 1053 |
* @param on {@code true} to enable TCP_NODELAY, |
1054 |
* {@code false} to disable. |
|
2 | 1055 |
* |
1056 |
* @exception SocketException if there is an error |
|
1057 |
* in the underlying protocol, such as a TCP error. |
|
1058 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1059 |
* @since 1.1 |
2 | 1060 |
* |
1061 |
* @see #getTcpNoDelay() |
|
1062 |
*/ |
|
1063 |
public void setTcpNoDelay(boolean on) throws SocketException { |
|
1064 |
if (isClosed()) |
|
1065 |
throw new SocketException("Socket is closed"); |
|
1066 |
getImpl().setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on)); |
|
1067 |
} |
|
1068 |
||
1069 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1070 |
* Tests if {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled. |
2 | 1071 |
* |
19069 | 1072 |
* @return a {@code boolean} indicating whether or not |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1073 |
* {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled. |
2 | 1074 |
* @exception SocketException if there is an error |
1075 |
* in the underlying protocol, such as a TCP error. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1076 |
* @since 1.1 |
2 | 1077 |
* @see #setTcpNoDelay(boolean) |
1078 |
*/ |
|
1079 |
public boolean getTcpNoDelay() throws SocketException { |
|
1080 |
if (isClosed()) |
|
1081 |
throw new SocketException("Socket is closed"); |
|
1082 |
return ((Boolean) getImpl().getOption(SocketOptions.TCP_NODELAY)).booleanValue(); |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1086 |
* Enable/disable {@link SocketOptions#SO_LINGER SO_LINGER} with the |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1087 |
* specified linger time in seconds. The maximum timeout value is platform |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1088 |
* specific. |
2 | 1089 |
* |
1090 |
* The setting only affects socket close. |
|
1091 |
* |
|
1092 |
* @param on whether or not to linger on. |
|
1093 |
* @param linger how long to linger for, if on is true. |
|
1094 |
* @exception SocketException if there is an error |
|
1095 |
* in the underlying protocol, such as a TCP error. |
|
1096 |
* @exception IllegalArgumentException if the linger value is negative. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1097 |
* @since 1.1 |
2 | 1098 |
* @see #getSoLinger() |
1099 |
*/ |
|
1100 |
public void setSoLinger(boolean on, int linger) throws SocketException { |
|
1101 |
if (isClosed()) |
|
1102 |
throw new SocketException("Socket is closed"); |
|
1103 |
if (!on) { |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
23879
diff
changeset
|
1104 |
getImpl().setOption(SocketOptions.SO_LINGER, on); |
2 | 1105 |
} else { |
1106 |
if (linger < 0) { |
|
1107 |
throw new IllegalArgumentException("invalid value for SO_LINGER"); |
|
1108 |
} |
|
1109 |
if (linger > 65535) |
|
1110 |
linger = 65535; |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24865
diff
changeset
|
1111 |
getImpl().setOption(SocketOptions.SO_LINGER, linger); |
2 | 1112 |
} |
1113 |
} |
|
1114 |
||
1115 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1116 |
* Returns setting for {@link SocketOptions#SO_LINGER SO_LINGER}. |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1117 |
* -1 returns implies that the |
2 | 1118 |
* option is disabled. |
1119 |
* |
|
1120 |
* The setting only affects socket close. |
|
1121 |
* |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1122 |
* @return the setting for {@link SocketOptions#SO_LINGER SO_LINGER}. |
2 | 1123 |
* @exception SocketException if there is an error |
1124 |
* in the underlying protocol, such as a TCP error. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1125 |
* @since 1.1 |
2 | 1126 |
* @see #setSoLinger(boolean, int) |
1127 |
*/ |
|
1128 |
public int getSoLinger() throws SocketException { |
|
1129 |
if (isClosed()) |
|
1130 |
throw new SocketException("Socket is closed"); |
|
1131 |
Object o = getImpl().getOption(SocketOptions.SO_LINGER); |
|
1132 |
if (o instanceof Integer) { |
|
1133 |
return ((Integer) o).intValue(); |
|
1134 |
} else { |
|
1135 |
return -1; |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1139 |
/** |
|
1140 |
* Send one byte of urgent data on the socket. The byte to be sent is the lowest eight |
|
1141 |
* bits of the data parameter. The urgent byte is |
|
1142 |
* sent after any preceding writes to the socket OutputStream |
|
1143 |
* and before any future writes to the OutputStream. |
|
1144 |
* @param data The byte of data to send |
|
1145 |
* @exception IOException if there is an error |
|
1146 |
* sending the data. |
|
1147 |
* @since 1.4 |
|
1148 |
*/ |
|
1149 |
public void sendUrgentData (int data) throws IOException { |
|
1150 |
if (!getImpl().supportsUrgentData ()) { |
|
1151 |
throw new SocketException ("Urgent data not supported"); |
|
1152 |
} |
|
1153 |
getImpl().sendUrgentData (data); |
|
1154 |
} |
|
1155 |
||
1156 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1157 |
* Enable/disable {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1158 |
* (receipt of TCP urgent data) |
2 | 1159 |
* |
1160 |
* By default, this option is disabled and TCP urgent data received on a |
|
1161 |
* socket is silently discarded. If the user wishes to receive urgent data, then |
|
1162 |
* this option must be enabled. When enabled, urgent data is received |
|
1163 |
* inline with normal data. |
|
1164 |
* <p> |
|
1165 |
* Note, only limited support is provided for handling incoming urgent |
|
1166 |
* data. In particular, no notification of incoming urgent data is provided |
|
1167 |
* and there is no capability to distinguish between normal data and urgent |
|
1168 |
* data unless provided by a higher level protocol. |
|
1169 |
* |
|
19069 | 1170 |
* @param on {@code true} to enable |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1171 |
* {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE}, |
19069 | 1172 |
* {@code false} to disable. |
2 | 1173 |
* |
1174 |
* @exception SocketException if there is an error |
|
1175 |
* in the underlying protocol, such as a TCP error. |
|
1176 |
* |
|
1177 |
* @since 1.4 |
|
1178 |
* |
|
1179 |
* @see #getOOBInline() |
|
1180 |
*/ |
|
1181 |
public void setOOBInline(boolean on) throws SocketException { |
|
1182 |
if (isClosed()) |
|
1183 |
throw new SocketException("Socket is closed"); |
|
1184 |
getImpl().setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(on)); |
|
1185 |
} |
|
1186 |
||
1187 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1188 |
* Tests if {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} is enabled. |
2 | 1189 |
* |
19069 | 1190 |
* @return a {@code boolean} indicating whether or not |
53133
bf2533105a26
8215912: Various Typos in java.net Method Documentation
coffeys
parents:
52499
diff
changeset
|
1191 |
* {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} is enabled. |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1192 |
* |
2 | 1193 |
* @exception SocketException if there is an error |
1194 |
* in the underlying protocol, such as a TCP error. |
|
1195 |
* @since 1.4 |
|
1196 |
* @see #setOOBInline(boolean) |
|
1197 |
*/ |
|
1198 |
public boolean getOOBInline() throws SocketException { |
|
1199 |
if (isClosed()) |
|
1200 |
throw new SocketException("Socket is closed"); |
|
1201 |
return ((Boolean) getImpl().getOption(SocketOptions.SO_OOBINLINE)).booleanValue(); |
|
1202 |
} |
|
1203 |
||
1204 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1205 |
* Enable/disable {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1206 |
* with the specified timeout, in milliseconds. With this option set |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1207 |
* to a non-zero timeout, a read() call on the InputStream associated with |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1208 |
* this Socket will block for only this amount of time. If the timeout |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1209 |
* expires, a <B>java.net.SocketTimeoutException</B> is raised, though the |
2 | 1210 |
* Socket is still valid. The option <B>must</B> be enabled |
1211 |
* prior to entering the blocking operation to have effect. The |
|
18156 | 1212 |
* timeout must be {@code > 0}. |
2 | 1213 |
* A timeout of zero is interpreted as an infinite timeout. |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1214 |
* |
2 | 1215 |
* @param timeout the specified timeout, in milliseconds. |
54289
6183f835b9b6
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
chegar
parents:
54155
diff
changeset
|
1216 |
* @throws SocketException if there is an error in the underlying protocol, |
6183f835b9b6
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
chegar
parents:
54155
diff
changeset
|
1217 |
* such as a TCP error |
6183f835b9b6
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
chegar
parents:
54155
diff
changeset
|
1218 |
* @throws IllegalArgumentException if {@code timeout} is negative |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1219 |
* @since 1.1 |
2 | 1220 |
* @see #getSoTimeout() |
1221 |
*/ |
|
1222 |
public synchronized void setSoTimeout(int timeout) throws SocketException { |
|
1223 |
if (isClosed()) |
|
1224 |
throw new SocketException("Socket is closed"); |
|
1225 |
if (timeout < 0) |
|
1226 |
throw new IllegalArgumentException("timeout can't be negative"); |
|
1227 |
||
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24865
diff
changeset
|
1228 |
getImpl().setOption(SocketOptions.SO_TIMEOUT, timeout); |
2 | 1229 |
} |
1230 |
||
1231 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1232 |
* Returns setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}. |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1233 |
* 0 returns implies that the option is disabled (i.e., timeout of infinity). |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1234 |
* |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1235 |
* @return the setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} |
2 | 1236 |
* @exception SocketException if there is an error |
1237 |
* in the underlying protocol, such as a TCP error. |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1238 |
* |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24685
diff
changeset
|
1239 |
* @since 1.1 |
2 | 1240 |
* @see #setSoTimeout(int) |
1241 |
*/ |
|
1242 |
public synchronized int getSoTimeout() throws SocketException { |
|
1243 |
if (isClosed()) |
|
1244 |
throw new SocketException("Socket is closed"); |
|
1245 |
Object o = getImpl().getOption(SocketOptions.SO_TIMEOUT); |
|
1246 |
/* extra type safety */ |
|
1247 |
if (o instanceof Integer) { |
|
1248 |
return ((Integer) o).intValue(); |
|
1249 |
} else { |
|
1250 |
return 0; |
|
1251 |
} |
|
1252 |
} |
|
1253 |
||
1254 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1255 |
* Sets the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option to the |
19069 | 1256 |
* specified value for this {@code Socket}. |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1257 |
* The {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option is used by the |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1258 |
* platform's networking code as a hint for the size to set the underlying |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1259 |
* network I/O buffers. |
2 | 1260 |
* |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1261 |
* <p>Because {@link SocketOptions#SO_SNDBUF SO_SNDBUF} is a hint, |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1262 |
* applications that want to verify what size the buffers were set to |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1263 |
* should call {@link #getSendBufferSize()}. |
2 | 1264 |
* |
1265 |
* @exception SocketException if there is an error |
|
1266 |
* in the underlying protocol, such as a TCP error. |
|
1267 |
* |
|
1268 |
* @param size the size to which to set the send buffer |
|
1269 |
* size. This value must be greater than 0. |
|
1270 |
* |
|
1271 |
* @exception IllegalArgumentException if the |
|
1272 |
* value is 0 or is negative. |
|
1273 |
* |
|
1274 |
* @see #getSendBufferSize() |
|
1275 |
* @since 1.2 |
|
1276 |
*/ |
|
1277 |
public synchronized void setSendBufferSize(int size) |
|
1278 |
throws SocketException{ |
|
1279 |
if (!(size > 0)) { |
|
1280 |
throw new IllegalArgumentException("negative send size"); |
|
1281 |
} |
|
1282 |
if (isClosed()) |
|
1283 |
throw new SocketException("Socket is closed"); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24865
diff
changeset
|
1284 |
getImpl().setOption(SocketOptions.SO_SNDBUF, size); |
2 | 1285 |
} |
1286 |
||
1287 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1288 |
* Get value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option |
19069 | 1289 |
* for this {@code Socket}, that is the buffer size used by the platform |
1290 |
* for output on this {@code Socket}. |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1291 |
* @return the value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} |
19069 | 1292 |
* option for this {@code Socket}. |
2 | 1293 |
* |
1294 |
* @exception SocketException if there is an error |
|
1295 |
* in the underlying protocol, such as a TCP error. |
|
1296 |
* |
|
1297 |
* @see #setSendBufferSize(int) |
|
1298 |
* @since 1.2 |
|
1299 |
*/ |
|
1300 |
public synchronized int getSendBufferSize() throws SocketException { |
|
1301 |
if (isClosed()) |
|
1302 |
throw new SocketException("Socket is closed"); |
|
1303 |
int result = 0; |
|
1304 |
Object o = getImpl().getOption(SocketOptions.SO_SNDBUF); |
|
1305 |
if (o instanceof Integer) { |
|
1306 |
result = ((Integer)o).intValue(); |
|
1307 |
} |
|
1308 |
return result; |
|
1309 |
} |
|
1310 |
||
1311 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1312 |
* Sets the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option to the |
19069 | 1313 |
* specified value for this {@code Socket}. The |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1314 |
* {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option is |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1315 |
* used by the platform's networking code as a hint for the size to set |
2 | 1316 |
* the underlying network I/O buffers. |
1317 |
* |
|
1318 |
* <p>Increasing the receive buffer size can increase the performance of |
|
1319 |
* network I/O for high-volume connection, while decreasing it can |
|
1320 |
* help reduce the backlog of incoming data. |
|
1321 |
* |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1322 |
* <p>Because {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is a hint, |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1323 |
* applications that want to verify what size the buffers were set to |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1324 |
* should call {@link #getReceiveBufferSize()}. |
2 | 1325 |
* |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1326 |
* <p>The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is also used |
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
52456
diff
changeset
|
1327 |
* to set the TCP receive window that is advertised to the remote peer. |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1328 |
* Generally, the window size can be modified at any time when a socket is |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1329 |
* connected. However, if a receive window larger than 64K is required then |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1330 |
* this must be requested <B>before</B> the socket is connected to the |
21334 | 1331 |
* remote peer. There are two cases to be aware of: |
2 | 1332 |
* <ol> |
1333 |
* <li>For sockets accepted from a ServerSocket, this must be done by calling |
|
1334 |
* {@link ServerSocket#setReceiveBufferSize(int)} before the ServerSocket |
|
23720
7d5147c21927
8039172: Tidy warnings cleanup for java.net, java.math, java.time, java.rmi
yan
parents:
22339
diff
changeset
|
1335 |
* is bound to a local address.</li> |
2 | 1336 |
* <li>For client sockets, setReceiveBufferSize() must be called before |
21334 | 1337 |
* connecting the socket to its remote peer.</li></ol> |
2 | 1338 |
* @param size the size to which to set the receive buffer |
1339 |
* size. This value must be greater than 0. |
|
1340 |
* |
|
1341 |
* @exception IllegalArgumentException if the value is 0 or is |
|
1342 |
* negative. |
|
1343 |
* |
|
1344 |
* @exception SocketException if there is an error |
|
1345 |
* in the underlying protocol, such as a TCP error. |
|
1346 |
* |
|
1347 |
* @see #getReceiveBufferSize() |
|
1348 |
* @see ServerSocket#setReceiveBufferSize(int) |
|
1349 |
* @since 1.2 |
|
1350 |
*/ |
|
1351 |
public synchronized void setReceiveBufferSize(int size) |
|
1352 |
throws SocketException{ |
|
1353 |
if (size <= 0) { |
|
1354 |
throw new IllegalArgumentException("invalid receive size"); |
|
1355 |
} |
|
1356 |
if (isClosed()) |
|
1357 |
throw new SocketException("Socket is closed"); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24865
diff
changeset
|
1358 |
getImpl().setOption(SocketOptions.SO_RCVBUF, size); |
2 | 1359 |
} |
1360 |
||
1361 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1362 |
* Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option |
19069 | 1363 |
* for this {@code Socket}, that is the buffer size used by the platform |
1364 |
* for input on this {@code Socket}. |
|
2 | 1365 |
* |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1366 |
* @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} |
19069 | 1367 |
* option for this {@code Socket}. |
2 | 1368 |
* @exception SocketException if there is an error |
1369 |
* in the underlying protocol, such as a TCP error. |
|
1370 |
* @see #setReceiveBufferSize(int) |
|
1371 |
* @since 1.2 |
|
1372 |
*/ |
|
1373 |
public synchronized int getReceiveBufferSize() |
|
1374 |
throws SocketException{ |
|
1375 |
if (isClosed()) |
|
1376 |
throw new SocketException("Socket is closed"); |
|
1377 |
int result = 0; |
|
1378 |
Object o = getImpl().getOption(SocketOptions.SO_RCVBUF); |
|
1379 |
if (o instanceof Integer) { |
|
1380 |
result = ((Integer)o).intValue(); |
|
1381 |
} |
|
1382 |
return result; |
|
1383 |
} |
|
1384 |
||
1385 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1386 |
* Enable/disable {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE}. |
2 | 1387 |
* |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1388 |
* @param on whether or not to have socket keep alive turned on. |
2 | 1389 |
* @exception SocketException if there is an error |
1390 |
* in the underlying protocol, such as a TCP error. |
|
1391 |
* @since 1.3 |
|
1392 |
* @see #getKeepAlive() |
|
1393 |
*/ |
|
1394 |
public void setKeepAlive(boolean on) throws SocketException { |
|
1395 |
if (isClosed()) |
|
1396 |
throw new SocketException("Socket is closed"); |
|
1397 |
getImpl().setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(on)); |
|
1398 |
} |
|
1399 |
||
1400 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1401 |
* Tests if {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled. |
2 | 1402 |
* |
19069 | 1403 |
* @return a {@code boolean} indicating whether or not |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1404 |
* {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled. |
2 | 1405 |
* @exception SocketException if there is an error |
1406 |
* in the underlying protocol, such as a TCP error. |
|
1407 |
* @since 1.3 |
|
1408 |
* @see #setKeepAlive(boolean) |
|
1409 |
*/ |
|
1410 |
public boolean getKeepAlive() throws SocketException { |
|
1411 |
if (isClosed()) |
|
1412 |
throw new SocketException("Socket is closed"); |
|
1413 |
return ((Boolean) getImpl().getOption(SocketOptions.SO_KEEPALIVE)).booleanValue(); |
|
1414 |
} |
|
1415 |
||
1416 |
/** |
|
1417 |
* Sets traffic class or type-of-service octet in the IP |
|
1418 |
* header for packets sent from this Socket. |
|
1419 |
* As the underlying network implementation may ignore this |
|
1420 |
* value applications should consider it a hint. |
|
1421 |
* |
|
18156 | 1422 |
* <P> The tc <B>must</B> be in the range {@code 0 <= tc <= |
1423 |
* 255} or an IllegalArgumentException will be thrown. |
|
2 | 1424 |
* <p>Notes: |
1425 |
* <p>For Internet Protocol v4 the value consists of an |
|
19069 | 1426 |
* {@code integer}, the least significant 8 bits of which |
2 | 1427 |
* represent the value of the TOS octet in IP packets sent by |
1428 |
* the socket. |
|
1429 |
* RFC 1349 defines the TOS values as follows: |
|
21334 | 1430 |
* |
2 | 1431 |
* <UL> |
1432 |
* <LI><CODE>IPTOS_LOWCOST (0x02)</CODE></LI> |
|
1433 |
* <LI><CODE>IPTOS_RELIABILITY (0x04)</CODE></LI> |
|
1434 |
* <LI><CODE>IPTOS_THROUGHPUT (0x08)</CODE></LI> |
|
1435 |
* <LI><CODE>IPTOS_LOWDELAY (0x10)</CODE></LI> |
|
1436 |
* </UL> |
|
1437 |
* The last low order bit is always ignored as this |
|
1438 |
* corresponds to the MBZ (must be zero) bit. |
|
1439 |
* <p> |
|
1440 |
* Setting bits in the precedence field may result in a |
|
1441 |
* SocketException indicating that the operation is not |
|
1442 |
* permitted. |
|
1443 |
* <p> |
|
1444 |
* As RFC 1122 section 4.2.4.2 indicates, a compliant TCP |
|
1445 |
* implementation should, but is not required to, let application |
|
1446 |
* change the TOS field during the lifetime of a connection. |
|
1447 |
* So whether the type-of-service field can be changed after the |
|
1448 |
* TCP connection has been established depends on the implementation |
|
1449 |
* in the underlying platform. Applications should not assume that |
|
1450 |
* they can change the TOS field after the connection. |
|
1451 |
* <p> |
|
19069 | 1452 |
* For Internet Protocol v6 {@code tc} is the value that |
2 | 1453 |
* would be placed into the sin6_flowinfo field of the IP header. |
1454 |
* |
|
19069 | 1455 |
* @param tc an {@code int} value for the bitset. |
2 | 1456 |
* @throws SocketException if there is an error setting the |
1457 |
* traffic class or type-of-service |
|
1458 |
* @since 1.4 |
|
1459 |
* @see #getTrafficClass |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1460 |
* @see SocketOptions#IP_TOS |
2 | 1461 |
*/ |
1462 |
public void setTrafficClass(int tc) throws SocketException { |
|
1463 |
if (tc < 0 || tc > 255) |
|
1464 |
throw new IllegalArgumentException("tc is not in range 0 -- 255"); |
|
1465 |
||
1466 |
if (isClosed()) |
|
1467 |
throw new SocketException("Socket is closed"); |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
1468 |
try { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
1469 |
getImpl().setOption(SocketOptions.IP_TOS, tc); |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
1470 |
} catch (SocketException se) { |
57336 | 1471 |
// not supported if socket already connected |
1472 |
// Solaris returns error in such cases |
|
1473 |
if(!isConnected()) |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
1474 |
throw se; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
1475 |
} |
2 | 1476 |
} |
1477 |
||
1478 |
/** |
|
1479 |
* Gets traffic class or type-of-service in the IP header |
|
1480 |
* for packets sent from this Socket |
|
1481 |
* <p> |
|
1482 |
* As the underlying network implementation may ignore the |
|
1483 |
* traffic class or type-of-service set using {@link #setTrafficClass(int)} |
|
1484 |
* this method may return a different value than was previously |
|
1485 |
* set using the {@link #setTrafficClass(int)} method on this Socket. |
|
1486 |
* |
|
1487 |
* @return the traffic class or type-of-service already set |
|
1488 |
* @throws SocketException if there is an error obtaining the |
|
1489 |
* traffic class or type-of-service value. |
|
1490 |
* @since 1.4 |
|
1491 |
* @see #setTrafficClass(int) |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1492 |
* @see SocketOptions#IP_TOS |
2 | 1493 |
*/ |
1494 |
public int getTrafficClass() throws SocketException { |
|
1495 |
return ((Integer) (getImpl().getOption(SocketOptions.IP_TOS))).intValue(); |
|
1496 |
} |
|
1497 |
||
1498 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1499 |
* Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1500 |
* socket option. |
2 | 1501 |
* <p> |
1502 |
* When a TCP connection is closed the connection may remain |
|
1503 |
* in a timeout state for a period of time after the connection |
|
19069 | 1504 |
* is closed (typically known as the {@code TIME_WAIT} state |
1505 |
* or {@code 2MSL} wait state). |
|
2 | 1506 |
* For applications using a well known socket address or port |
1507 |
* it may not be possible to bind a socket to the required |
|
19069 | 1508 |
* {@code SocketAddress} if there is a connection in the |
2 | 1509 |
* timeout state involving the socket address or port. |
1510 |
* <p> |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1511 |
* Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1512 |
* prior to binding the socket using {@link #bind(SocketAddress)} allows |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1513 |
* the socket to be bound even though a previous connection is in a timeout |
2 | 1514 |
* state. |
1515 |
* <p> |
|
19069 | 1516 |
* When a {@code Socket} is created the initial setting |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1517 |
* of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is disabled. |
2 | 1518 |
* <p> |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1519 |
* The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1520 |
* enabled or disabled after a socket is bound (See {@link #isBound()}) |
2 | 1521 |
* is not defined. |
1522 |
* |
|
1523 |
* @param on whether to enable or disable the socket option |
|
1524 |
* @exception SocketException if an error occurs enabling or |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1525 |
* disabling the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} |
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1526 |
* socket option, or the socket is closed. |
2 | 1527 |
* @since 1.4 |
1528 |
* @see #getReuseAddress() |
|
1529 |
* @see #bind(SocketAddress) |
|
1530 |
* @see #isClosed() |
|
1531 |
* @see #isBound() |
|
1532 |
*/ |
|
1533 |
public void setReuseAddress(boolean on) throws SocketException { |
|
1534 |
if (isClosed()) |
|
1535 |
throw new SocketException("Socket is closed"); |
|
1536 |
getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); |
|
1537 |
} |
|
1538 |
||
1539 |
/** |
|
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1540 |
* Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. |
2 | 1541 |
* |
19069 | 1542 |
* @return a {@code boolean} indicating whether or not |
17469
e00a02431a8b
6328537: Improve javadocs for Socket class by adding references to SocketOptions
khazra
parents:
16061
diff
changeset
|
1543 |
* {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. |
2 | 1544 |
* @exception SocketException if there is an error |
1545 |
* in the underlying protocol, such as a TCP error. |
|
1546 |
* @since 1.4 |
|
1547 |
* @see #setReuseAddress(boolean) |
|
1548 |
*/ |
|
1549 |
public boolean getReuseAddress() throws SocketException { |
|
1550 |
if (isClosed()) |
|
1551 |
throw new SocketException("Socket is closed"); |
|
1552 |
return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue(); |
|
1553 |
} |
|
1554 |
||
1555 |
/** |
|
1556 |
* Closes this socket. |
|
1557 |
* <p> |
|
1558 |
* Any thread currently blocked in an I/O operation upon this socket |
|
1559 |
* will throw a {@link SocketException}. |
|
1560 |
* <p> |
|
1561 |
* Once a socket has been closed, it is not available for further networking |
|
1562 |
* use (i.e. can't be reconnected or rebound). A new socket needs to be |
|
1563 |
* created. |
|
1564 |
* |
|
1565 |
* <p> Closing this socket will also close the socket's |
|
1566 |
* {@link java.io.InputStream InputStream} and |
|
1567 |
* {@link java.io.OutputStream OutputStream}. |
|
1568 |
* |
|
1569 |
* <p> If this socket has an associated channel then the channel is closed |
|
1570 |
* as well. |
|
1571 |
* |
|
1572 |
* @exception IOException if an I/O error occurs when closing this socket. |
|
1573 |
* @revised 1.4 |
|
1574 |
* @spec JSR-51 |
|
1575 |
* @see #isClosed |
|
1576 |
*/ |
|
57344 | 1577 |
public synchronized void close() throws IOException { |
1578 |
synchronized(closeLock) { |
|
1579 |
if (isClosed()) |
|
57341 | 1580 |
return; |
1581 |
if (created) |
|
1582 |
impl.close(); |
|
57344 | 1583 |
closed = true; |
2 | 1584 |
} |
1585 |
} |
|
1586 |
||
1587 |
/** |
|
1588 |
* Places the input stream for this socket at "end of stream". |
|
1589 |
* Any data sent to the input stream side of the socket is acknowledged |
|
1590 |
* and then silently discarded. |
|
1591 |
* <p> |
|
10421
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9775
diff
changeset
|
1592 |
* If you read from a socket input stream after invoking this method on the |
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9775
diff
changeset
|
1593 |
* socket, the stream's {@code available} method will return 0, and its |
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9775
diff
changeset
|
1594 |
* {@code read} methods will return {@code -1} (end of stream). |
2 | 1595 |
* |
1596 |
* @exception IOException if an I/O error occurs when shutting down this |
|
1597 |
* socket. |
|
1598 |
* |
|
1599 |
* @since 1.3 |
|
1600 |
* @see java.net.Socket#shutdownOutput() |
|
1601 |
* @see java.net.Socket#close() |
|
1602 |
* @see java.net.Socket#setSoLinger(boolean, int) |
|
1603 |
* @see #isInputShutdown |
|
1604 |
*/ |
|
1605 |
public void shutdownInput() throws IOException |
|
1606 |
{ |
|
1607 |
if (isClosed()) |
|
1608 |
throw new SocketException("Socket is closed"); |
|
1609 |
if (!isConnected()) |
|
1610 |
throw new SocketException("Socket is not connected"); |
|
1611 |
if (isInputShutdown()) |
|
1612 |
throw new SocketException("Socket input is already shutdown"); |
|
1613 |
getImpl().shutdownInput(); |
|
1614 |
shutIn = true; |
|
1615 |
} |
|
1616 |
||
1617 |
/** |
|
1618 |
* Disables the output stream for this socket. |
|
1619 |
* For a TCP socket, any previously written data will be sent |
|
1620 |
* followed by TCP's normal connection termination sequence. |
|
1621 |
* |
|
1622 |
* If you write to a socket output stream after invoking |
|
1623 |
* shutdownOutput() on the socket, the stream will throw |
|
1624 |
* an IOException. |
|
1625 |
* |
|
1626 |
* @exception IOException if an I/O error occurs when shutting down this |
|
1627 |
* socket. |
|
1628 |
* |
|
1629 |
* @since 1.3 |
|
1630 |
* @see java.net.Socket#shutdownInput() |
|
1631 |
* @see java.net.Socket#close() |
|
1632 |
* @see java.net.Socket#setSoLinger(boolean, int) |
|
1633 |
* @see #isOutputShutdown |
|
1634 |
*/ |
|
1635 |
public void shutdownOutput() throws IOException |
|
1636 |
{ |
|
1637 |
if (isClosed()) |
|
1638 |
throw new SocketException("Socket is closed"); |
|
1639 |
if (!isConnected()) |
|
1640 |
throw new SocketException("Socket is not connected"); |
|
1641 |
if (isOutputShutdown()) |
|
1642 |
throw new SocketException("Socket output is already shutdown"); |
|
1643 |
getImpl().shutdownOutput(); |
|
1644 |
shutOut = true; |
|
1645 |
} |
|
1646 |
||
1647 |
/** |
|
19069 | 1648 |
* Converts this socket to a {@code String}. |
2 | 1649 |
* |
1650 |
* @return a string representation of this socket. |
|
1651 |
*/ |
|
1652 |
public String toString() { |
|
1653 |
try { |
|
1654 |
if (isConnected()) |
|
1655 |
return "Socket[addr=" + getImpl().getInetAddress() + |
|
1656 |
",port=" + getImpl().getPort() + |
|
1657 |
",localport=" + getImpl().getLocalPort() + "]"; |
|
1658 |
} catch (SocketException e) { |
|
1659 |
} |
|
1660 |
return "Socket[unconnected]"; |
|
1661 |
} |
|
1662 |
||
1663 |
/** |
|
1664 |
* Returns the connection state of the socket. |
|
1665 |
* <p> |
|
1666 |
* Note: Closing a socket doesn't clear its connection state, which means |
|
19069 | 1667 |
* this method will return {@code true} for a closed socket |
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
52456
diff
changeset
|
1668 |
* (see {@link #isClosed()}) if it was successfully connected prior |
2 | 1669 |
* to being closed. |
1670 |
* |
|
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
52456
diff
changeset
|
1671 |
* @return true if the socket was successfully connected to a server |
2 | 1672 |
* @since 1.4 |
1673 |
*/ |
|
1674 |
public boolean isConnected() { |
|
1675 |
// Before 1.3 Sockets were always connected during creation |
|
1676 |
return connected || oldImpl; |
|
1677 |
} |
|
1678 |
||
1679 |
/** |
|
1680 |
* Returns the binding state of the socket. |
|
1681 |
* <p> |
|
1682 |
* Note: Closing a socket doesn't clear its binding state, which means |
|
19069 | 1683 |
* this method will return {@code true} for a closed socket |
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
52456
diff
changeset
|
1684 |
* (see {@link #isClosed()}) if it was successfully bound prior |
2 | 1685 |
* to being closed. |
1686 |
* |
|
52499
768b1c612100
8213490: Networking area typos and inconsistencies cleanup
prappo
parents:
52456
diff
changeset
|
1687 |
* @return true if the socket was successfully bound to an address |
2 | 1688 |
* @since 1.4 |
1689 |
* @see #bind |
|
1690 |
*/ |
|
1691 |
public boolean isBound() { |
|
1692 |
// Before 1.3 Sockets were always bound during creation |
|
1693 |
return bound || oldImpl; |
|
1694 |
} |
|
1695 |
||
1696 |
/** |
|
1697 |
* Returns the closed state of the socket. |
|
1698 |
* |
|
1699 |
* @return true if the socket has been closed |
|
1700 |
* @since 1.4 |
|
1701 |
* @see #close |
|
1702 |
*/ |
|
1703 |
public boolean isClosed() { |
|
57344 | 1704 |
synchronized(closeLock) { |
2 | 1705 |
return closed; |
1706 |
} |
|
1707 |
} |
|
1708 |
||
1709 |
/** |
|
1710 |
* Returns whether the read-half of the socket connection is closed. |
|
1711 |
* |
|
1712 |
* @return true if the input of the socket has been shutdown |
|
1713 |
* @since 1.4 |
|
1714 |
* @see #shutdownInput |
|
1715 |
*/ |
|
1716 |
public boolean isInputShutdown() { |
|
1717 |
return shutIn; |
|
1718 |
} |
|
1719 |
||
1720 |
/** |
|
1721 |
* Returns whether the write-half of the socket connection is closed. |
|
1722 |
* |
|
1723 |
* @return true if the output of the socket has been shutdown |
|
1724 |
* @since 1.4 |
|
1725 |
* @see #shutdownOutput |
|
1726 |
*/ |
|
1727 |
public boolean isOutputShutdown() { |
|
1728 |
return shutOut; |
|
1729 |
} |
|
1730 |
||
1731 |
/** |
|
1732 |
* The factory for all client sockets. |
|
1733 |
*/ |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1734 |
private static volatile SocketImplFactory factory; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1735 |
|
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1736 |
static SocketImplFactory socketImplFactory() { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1737 |
return factory; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
53133
diff
changeset
|
1738 |
} |
2 | 1739 |
|
1740 |
/** |
|
1741 |
* Sets the client socket implementation factory for the |
|
1742 |
* application. The factory can be specified only once. |
|
1743 |
* <p> |
|
1744 |
* When an application creates a new client socket, the socket |
|
19069 | 1745 |
* implementation factory's {@code createSocketImpl} method is |
2 | 1746 |
* called to create the actual socket implementation. |
1747 |
* <p> |
|
19069 | 1748 |
* Passing {@code null} to the method is a no-op unless the factory |
2 | 1749 |
* was already set. |
1750 |
* <p>If there is a security manager, this method first calls |
|
19069 | 1751 |
* the security manager's {@code checkSetFactory} method |
2 | 1752 |
* to ensure the operation is allowed. |
1753 |
* This could result in a SecurityException. |
|
1754 |
* |
|
1755 |
* @param fac the desired factory. |
|
1756 |
* @exception IOException if an I/O error occurs when setting the |
|
1757 |
* socket factory. |
|
1758 |
* @exception SocketException if the factory is already defined. |
|
1759 |
* @exception SecurityException if a security manager exists and its |
|
19069 | 1760 |
* {@code checkSetFactory} method doesn't allow the operation. |
2 | 1761 |
* @see java.net.SocketImplFactory#createSocketImpl() |
1762 |
* @see SecurityManager#checkSetFactory |
|
1763 |
*/ |
|
1764 |
public static synchronized void setSocketImplFactory(SocketImplFactory fac) |
|
1765 |
throws IOException |
|
1766 |
{ |
|
1767 |
if (factory != null) { |
|
1768 |
throw new SocketException("factory already defined"); |
|
1769 |
} |
|
1770 |
SecurityManager security = System.getSecurityManager(); |
|
1771 |
if (security != null) { |
|
1772 |
security.checkSetFactory(); |
|
1773 |
} |
|
1774 |
factory = fac; |
|
1775 |
} |
|
1776 |
||
1777 |
/** |
|
1778 |
* Sets performance preferences for this socket. |
|
1779 |
* |
|
1780 |
* <p> Sockets use the TCP/IP protocol by default. Some implementations |
|
1781 |
* may offer alternative protocols which have different performance |
|
1782 |
* characteristics than TCP/IP. This method allows the application to |
|
1783 |
* express its own preferences as to how these tradeoffs should be made |
|
1784 |
* when the implementation chooses from the available protocols. |
|
1785 |
* |
|
1786 |
* <p> Performance preferences are described by three integers |
|
1787 |
* whose values indicate the relative importance of short connection time, |
|
1788 |
* low latency, and high bandwidth. The absolute values of the integers |
|
1789 |
* are irrelevant; in order to choose a protocol the values are simply |
|
1790 |
* compared, with larger values indicating stronger preferences. Negative |
|
1791 |
* values represent a lower priority than positive values. If the |
|
1792 |
* application prefers short connection time over both low latency and high |
|
1793 |
* bandwidth, for example, then it could invoke this method with the values |
|
19069 | 1794 |
* {@code (1, 0, 0)}. If the application prefers high bandwidth above low |
2 | 1795 |
* latency, and low latency above short connection time, then it could |
19069 | 1796 |
* invoke this method with the values {@code (0, 1, 2)}. |
2 | 1797 |
* |
1798 |
* <p> Invoking this method after this socket has been connected |
|
1799 |
* will have no effect. |
|
1800 |
* |
|
1801 |
* @param connectionTime |
|
19069 | 1802 |
* An {@code int} expressing the relative importance of a short |
2 | 1803 |
* connection time |
1804 |
* |
|
1805 |
* @param latency |
|
19069 | 1806 |
* An {@code int} expressing the relative importance of low |
2 | 1807 |
* latency |
1808 |
* |
|
1809 |
* @param bandwidth |
|
19069 | 1810 |
* An {@code int} expressing the relative importance of high |
2 | 1811 |
* bandwidth |
1812 |
* |
|
1813 |
* @since 1.5 |
|
1814 |
*/ |
|
1815 |
public void setPerformancePreferences(int connectionTime, |
|
1816 |
int latency, |
|
1817 |
int bandwidth) |
|
1818 |
{ |
|
1819 |
/* Not implemented yet */ |
|
1820 |
} |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1821 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1822 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1823 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1824 |
* Sets the value of a socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1825 |
* |
28852
a581c7868768
8041395: Doclint regression in java.net.SocketOption
darcy
parents:
25859
diff
changeset
|
1826 |
* @param <T> The type of the socket option value |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1827 |
* @param name The socket option |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1828 |
* @param value The value of the socket option. A value of {@code null} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1829 |
* may be valid for some options. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1830 |
* @return this Socket |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1831 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1832 |
* @throws UnsupportedOperationException if the socket does not support |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1833 |
* the option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1834 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1835 |
* @throws IllegalArgumentException if the value is not valid for |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1836 |
* the option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1837 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1838 |
* @throws IOException if an I/O error occurs, or if the socket is closed. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1839 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1840 |
* @throws NullPointerException if name is {@code null} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1841 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1842 |
* @throws SecurityException if a security manager is set and if the socket |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1843 |
* option requires a security permission and if the caller does |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1844 |
* not have the required permission. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1845 |
* {@link java.net.StandardSocketOptions StandardSocketOptions} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1846 |
* do not require any security permission. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1847 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
30963
diff
changeset
|
1848 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1849 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1850 |
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException { |
57336 | 1851 |
getImpl().setOption(name, value); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1852 |
return this; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1853 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1854 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1855 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1856 |
* Returns the value of a socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1857 |
* |
28852
a581c7868768
8041395: Doclint regression in java.net.SocketOption
darcy
parents:
25859
diff
changeset
|
1858 |
* @param <T> The type of the socket option value |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1859 |
* @param name The socket option |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1860 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1861 |
* @return The value of the socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1862 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1863 |
* @throws UnsupportedOperationException if the socket does not support |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1864 |
* the option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1865 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1866 |
* @throws IOException if an I/O error occurs, or if the socket is closed. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1867 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1868 |
* @throws NullPointerException if name is {@code null} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1869 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1870 |
* @throws SecurityException if a security manager is set and if the socket |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1871 |
* option requires a security permission and if the caller does |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1872 |
* not have the required permission. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1873 |
* {@link java.net.StandardSocketOptions StandardSocketOptions} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1874 |
* do not require any security permission. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1875 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
30963
diff
changeset
|
1876 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1877 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1878 |
@SuppressWarnings("unchecked") |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1879 |
public <T> T getOption(SocketOption<T> name) throws IOException { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1880 |
return getImpl().getOption(name); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1881 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1882 |
|
52456
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1883 |
// cache of unmodifiable impl options. Possibly set racy, in impl we trust |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1884 |
private volatile Set<SocketOption<?>> options; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1885 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1886 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1887 |
* Returns a set of the socket options supported by this socket. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1888 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1889 |
* This method will continue to return the set of options even after |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1890 |
* the socket has been closed. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1891 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1892 |
* @return A set of the socket options supported by this socket. This set |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1893 |
* may be empty if the socket's SocketImpl cannot be created. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1894 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
30963
diff
changeset
|
1895 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1896 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1897 |
public Set<SocketOption<?>> supportedOptions() { |
52456
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1898 |
Set<SocketOption<?>> so = options; |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1899 |
if (so != null) |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1900 |
return so; |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1901 |
|
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1902 |
try { |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1903 |
SocketImpl impl = getImpl(); |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1904 |
options = Collections.unmodifiableSet(impl.supportedOptions()); |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1905 |
} catch (IOException e) { |
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1906 |
options = Collections.emptySet(); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1907 |
} |
52456
90ff0e286a5e
8213418: Socket/ServerSocket supportedOptions does not work with custom SocketImpl
chegar
parents:
47216
diff
changeset
|
1908 |
return options; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
23720
diff
changeset
|
1909 |
} |
2 | 1910 |
} |