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