author | alanb |
Wed, 29 May 2019 20:58:35 +0100 | |
branch | niosocketimpl-branch |
changeset 57382 | 14e01d39c01a |
parent 57347 | 16c087c9103e |
parent 55081 | dd321e3596c0 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
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 |
||
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
28 |
import java.io.FileDescriptor; |
2 | 29 |
import java.io.IOException; |
30 |
import java.io.InputStream; |
|
31 |
import java.io.OutputStream; |
|
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
32 |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
33 |
import java.security.AccessController; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
34 |
import java.security.PrivilegedActionException; |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
35 |
import java.security.PrivilegedExceptionAction; |
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
36 |
import java.util.Collections; |
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
37 |
import java.util.HashSet; |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
38 |
import java.util.Objects; |
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
39 |
import java.util.Set; |
2 | 40 |
|
41 |
import sun.net.ConnectionResetException; |
|
2446 | 42 |
import sun.net.NetHooks; |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
43 |
import sun.net.PlatformSocketImpl; |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
44 |
import sun.net.ResourceManager; |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
45 |
import sun.net.ext.ExtendedSocketOptions; |
50722
bc104aaf24e9
8204233: Add configurable option for enhanced socket IOException messages
michaelm
parents:
49249
diff
changeset
|
46 |
import sun.net.util.SocketExceptions; |
2 | 47 |
|
48 |
/** |
|
49 |
* Default Socket Implementation. This implementation does |
|
50 |
* not implement any security checks. |
|
51 |
* Note this class should <b>NOT</b> be public. |
|
52 |
* |
|
53 |
* @author Steven B. Byrne |
|
54 |
*/ |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
55 |
abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSocketImpl { |
2 | 56 |
/* instance variable for SO_TIMEOUT */ |
57 |
int timeout; // timeout in millisec |
|
58 |
// traffic class |
|
59 |
private int trafficClass; |
|
60 |
||
61 |
private boolean shut_rd = false; |
|
62 |
private boolean shut_wr = false; |
|
63 |
||
64 |
private SocketInputStream socketInputStream = null; |
|
14173
8a94baea7747
7181793: Socket getOutputStream create streams that cannot be GC'ed until Socket is closed
coffeys
parents:
14014
diff
changeset
|
65 |
private SocketOutputStream socketOutputStream = null; |
2 | 66 |
|
67 |
/* number of threads using the FileDescriptor */ |
|
68 |
protected int fdUseCount = 0; |
|
69 |
||
70 |
/* lock when increment/decrementing fdUseCount */ |
|
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
71 |
protected final Object fdLock = new Object(); |
2 | 72 |
|
73 |
/* indicates a close is pending on the file descriptor */ |
|
74 |
protected boolean closePending = false; |
|
75 |
||
76 |
/* indicates connection reset state */ |
|
49249
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
77 |
private volatile boolean connectionReset; |
2 | 78 |
|
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
79 |
/* indicates whether impl is bound */ |
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
80 |
boolean isBound; |
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
81 |
|
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
82 |
/* indicates whether impl is connected */ |
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
83 |
volatile boolean isConnected; |
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
84 |
|
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
85 |
/* whether this Socket is a stream (TCP) socket or not (UDP) |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
86 |
*/ |
10708
f255532bf336
7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents:
10704
diff
changeset
|
87 |
protected boolean stream; |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
88 |
|
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
89 |
/* whether this is a server or not */ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
90 |
final boolean isServer; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
91 |
|
2 | 92 |
/** |
93 |
* Load net library into runtime. |
|
94 |
*/ |
|
95 |
static { |
|
96 |
java.security.AccessController.doPrivileged( |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
25859
diff
changeset
|
97 |
new java.security.PrivilegedAction<>() { |
12559
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
10708
diff
changeset
|
98 |
public Void run() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
10708
diff
changeset
|
99 |
System.loadLibrary("net"); |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
10708
diff
changeset
|
100 |
return null; |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
10708
diff
changeset
|
101 |
} |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
10708
diff
changeset
|
102 |
}); |
2 | 103 |
} |
104 |
||
36115 | 105 |
private static volatile boolean checkedReusePort; |
106 |
private static volatile boolean isReusePortAvailable; |
|
107 |
||
108 |
/** |
|
109 |
* Tells whether SO_REUSEPORT is supported. |
|
110 |
*/ |
|
111 |
static boolean isReusePortAvailable() { |
|
112 |
if (!checkedReusePort) { |
|
113 |
isReusePortAvailable = isReusePortAvailable0(); |
|
114 |
checkedReusePort = true; |
|
115 |
} |
|
116 |
return isReusePortAvailable; |
|
117 |
} |
|
118 |
||
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
119 |
AbstractPlainSocketImpl(boolean isServer) { |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
120 |
this.isServer = isServer; |
36115 | 121 |
} |
122 |
||
2 | 123 |
/** |
124 |
* Creates a socket with a boolean that specifies whether this |
|
125 |
* is a stream socket (true) or an unconnected UDP socket (false). |
|
126 |
*/ |
|
127 |
protected synchronized void create(boolean stream) throws IOException { |
|
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
128 |
this.stream = stream; |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
129 |
if (!stream) { |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
130 |
ResourceManager.beforeUdpCreate(); |
10704
db5816a6e8c7
7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents:
10421
diff
changeset
|
131 |
// only create the fd after we know we will be able to create the socket |
db5816a6e8c7
7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents:
10421
diff
changeset
|
132 |
fd = new FileDescriptor(); |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
133 |
try { |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
134 |
socketCreate(false); |
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
135 |
SocketCleanable.register(fd); |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
136 |
} catch (IOException ioe) { |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
137 |
ResourceManager.afterUdpClose(); |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
138 |
fd = null; |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
139 |
throw ioe; |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
140 |
} |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
141 |
} else { |
10704
db5816a6e8c7
7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents:
10421
diff
changeset
|
142 |
fd = new FileDescriptor(); |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
143 |
socketCreate(true); |
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
144 |
SocketCleanable.register(fd); |
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
145 |
} |
2 | 146 |
} |
147 |
||
148 |
/** |
|
149 |
* Creates a socket and connects it to the specified port on |
|
150 |
* the specified host. |
|
151 |
* @param host the specified host |
|
152 |
* @param port the specified port |
|
153 |
*/ |
|
154 |
protected void connect(String host, int port) |
|
155 |
throws UnknownHostException, IOException |
|
156 |
{ |
|
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
157 |
boolean connected = false; |
2 | 158 |
try { |
159 |
InetAddress address = InetAddress.getByName(host); |
|
160 |
this.port = port; |
|
161 |
this.address = address; |
|
162 |
||
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
163 |
connectToAddress(address, port, timeout); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
164 |
connected = true; |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
165 |
} finally { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
166 |
if (!connected) { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
167 |
try { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
168 |
close(); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
169 |
} catch (IOException ioe) { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
170 |
/* Do nothing. If connect threw an exception then |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
171 |
it will be passed up the call stack */ |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
172 |
} |
2 | 173 |
} |
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
174 |
isConnected = connected; |
2 | 175 |
} |
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Creates a socket and connects it to the specified address on |
|
180 |
* the specified port. |
|
181 |
* @param address the address |
|
182 |
* @param port the specified port |
|
183 |
*/ |
|
184 |
protected void connect(InetAddress address, int port) throws IOException { |
|
185 |
this.port = port; |
|
186 |
this.address = address; |
|
187 |
||
188 |
try { |
|
189 |
connectToAddress(address, port, timeout); |
|
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
190 |
isConnected = true; |
2 | 191 |
return; |
192 |
} catch (IOException e) { |
|
193 |
// everything failed |
|
194 |
close(); |
|
195 |
throw e; |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Creates a socket and connects it to the specified address on |
|
201 |
* the specified port. |
|
202 |
* @param address the address |
|
203 |
* @param timeout the timeout value in milliseconds, or zero for no timeout. |
|
204 |
* @throws IOException if connection fails |
|
205 |
* @throws IllegalArgumentException if address is null or is a |
|
206 |
* SocketAddress subclass not supported by this socket |
|
207 |
* @since 1.4 |
|
208 |
*/ |
|
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
209 |
protected void connect(SocketAddress address, int timeout) |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
210 |
throws IOException { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
211 |
boolean connected = false; |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
212 |
try { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
213 |
if (address == null || !(address instanceof InetSocketAddress)) |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
214 |
throw new IllegalArgumentException("unsupported address type"); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
215 |
InetSocketAddress addr = (InetSocketAddress) address; |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
216 |
if (addr.isUnresolved()) |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
217 |
throw new UnknownHostException(addr.getHostName()); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
218 |
this.port = addr.getPort(); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
219 |
this.address = addr.getAddress(); |
2 | 220 |
|
221 |
connectToAddress(this.address, port, timeout); |
|
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
222 |
connected = true; |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
223 |
} finally { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
224 |
if (!connected) { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
225 |
try { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
226 |
close(); |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
227 |
} catch (IOException ioe) { |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
228 |
/* Do nothing. If connect threw an exception then |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
229 |
it will be passed up the call stack */ |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
230 |
} |
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
231 |
} |
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
232 |
isConnected = connected; |
2 | 233 |
} |
234 |
} |
|
235 |
||
236 |
private void connectToAddress(InetAddress address, int port, int timeout) throws IOException { |
|
237 |
if (address.isAnyLocalAddress()) { |
|
238 |
doConnect(InetAddress.getLocalHost(), port, timeout); |
|
239 |
} else { |
|
240 |
doConnect(address, port, timeout); |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
public void setOption(int opt, Object val) throws SocketException { |
|
245 |
if (isClosedOrPending()) { |
|
246 |
throw new SocketException("Socket Closed"); |
|
247 |
} |
|
248 |
boolean on = true; |
|
249 |
switch (opt) { |
|
250 |
/* check type safety b4 going native. These should never |
|
251 |
* fail, since only java.Socket* has access to |
|
252 |
* PlainSocketImpl.setOption(). |
|
253 |
*/ |
|
254 |
case SO_LINGER: |
|
255 |
if (val == null || (!(val instanceof Integer) && !(val instanceof Boolean))) |
|
256 |
throw new SocketException("Bad parameter for option"); |
|
257 |
if (val instanceof Boolean) { |
|
258 |
/* true only if disabling - enabling should be Integer */ |
|
259 |
on = false; |
|
260 |
} |
|
261 |
break; |
|
262 |
case SO_TIMEOUT: |
|
263 |
if (val == null || (!(val instanceof Integer))) |
|
264 |
throw new SocketException("Bad parameter for SO_TIMEOUT"); |
|
265 |
int tmp = ((Integer) val).intValue(); |
|
266 |
if (tmp < 0) |
|
267 |
throw new IllegalArgumentException("timeout < 0"); |
|
268 |
timeout = tmp; |
|
269 |
break; |
|
270 |
case IP_TOS: |
|
271 |
if (val == null || !(val instanceof Integer)) { |
|
272 |
throw new SocketException("bad argument for IP_TOS"); |
|
273 |
} |
|
274 |
trafficClass = ((Integer)val).intValue(); |
|
275 |
break; |
|
276 |
case SO_BINDADDR: |
|
277 |
throw new SocketException("Cannot re-bind socket"); |
|
278 |
case TCP_NODELAY: |
|
279 |
if (val == null || !(val instanceof Boolean)) |
|
280 |
throw new SocketException("bad parameter for TCP_NODELAY"); |
|
281 |
on = ((Boolean)val).booleanValue(); |
|
282 |
break; |
|
283 |
case SO_SNDBUF: |
|
284 |
case SO_RCVBUF: |
|
285 |
if (val == null || !(val instanceof Integer) || |
|
286 |
!(((Integer)val).intValue() > 0)) { |
|
287 |
throw new SocketException("bad parameter for SO_SNDBUF " + |
|
288 |
"or SO_RCVBUF"); |
|
289 |
} |
|
290 |
break; |
|
291 |
case SO_KEEPALIVE: |
|
292 |
if (val == null || !(val instanceof Boolean)) |
|
293 |
throw new SocketException("bad parameter for SO_KEEPALIVE"); |
|
294 |
on = ((Boolean)val).booleanValue(); |
|
295 |
break; |
|
296 |
case SO_OOBINLINE: |
|
297 |
if (val == null || !(val instanceof Boolean)) |
|
298 |
throw new SocketException("bad parameter for SO_OOBINLINE"); |
|
299 |
on = ((Boolean)val).booleanValue(); |
|
300 |
break; |
|
301 |
case SO_REUSEADDR: |
|
302 |
if (val == null || !(val instanceof Boolean)) |
|
303 |
throw new SocketException("bad parameter for SO_REUSEADDR"); |
|
304 |
on = ((Boolean)val).booleanValue(); |
|
305 |
break; |
|
36115 | 306 |
case SO_REUSEPORT: |
307 |
if (val == null || !(val instanceof Boolean)) |
|
308 |
throw new SocketException("bad parameter for SO_REUSEPORT"); |
|
309 |
if (!supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) |
|
310 |
throw new UnsupportedOperationException("unsupported option"); |
|
311 |
on = ((Boolean)val).booleanValue(); |
|
312 |
break; |
|
2 | 313 |
default: |
314 |
throw new SocketException("unrecognized TCP option: " + opt); |
|
315 |
} |
|
316 |
socketSetOption(opt, on, val); |
|
317 |
} |
|
318 |
public Object getOption(int opt) throws SocketException { |
|
319 |
if (isClosedOrPending()) { |
|
320 |
throw new SocketException("Socket Closed"); |
|
321 |
} |
|
322 |
if (opt == SO_TIMEOUT) { |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
23010
diff
changeset
|
323 |
return timeout; |
2 | 324 |
} |
325 |
int ret = 0; |
|
326 |
/* |
|
327 |
* The native socketGetOption() knows about 3 options. |
|
328 |
* The 32 bit value it returns will be interpreted according |
|
329 |
* to what we're asking. A return of -1 means it understands |
|
330 |
* the option but its turned off. It will raise a SocketException |
|
331 |
* if "opt" isn't one it understands. |
|
332 |
*/ |
|
333 |
||
334 |
switch (opt) { |
|
335 |
case TCP_NODELAY: |
|
336 |
ret = socketGetOption(opt, null); |
|
337 |
return Boolean.valueOf(ret != -1); |
|
338 |
case SO_OOBINLINE: |
|
339 |
ret = socketGetOption(opt, null); |
|
340 |
return Boolean.valueOf(ret != -1); |
|
341 |
case SO_LINGER: |
|
342 |
ret = socketGetOption(opt, null); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
23010
diff
changeset
|
343 |
return (ret == -1) ? Boolean.FALSE: (Object)(ret); |
2 | 344 |
case SO_REUSEADDR: |
345 |
ret = socketGetOption(opt, null); |
|
346 |
return Boolean.valueOf(ret != -1); |
|
347 |
case SO_BINDADDR: |
|
348 |
InetAddressContainer in = new InetAddressContainer(); |
|
349 |
ret = socketGetOption(opt, in); |
|
350 |
return in.addr; |
|
351 |
case SO_SNDBUF: |
|
352 |
case SO_RCVBUF: |
|
353 |
ret = socketGetOption(opt, null); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
23010
diff
changeset
|
354 |
return ret; |
2 | 355 |
case IP_TOS: |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
356 |
try { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
357 |
ret = socketGetOption(opt, null); |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
358 |
if (ret == -1) { // ipv6 tos |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
359 |
return trafficClass; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
360 |
} else { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
361 |
return ret; |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
362 |
} |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
363 |
} catch (SocketException se) { |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
364 |
// TODO - should make better effort to read TOS or TCLASS |
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
29986
diff
changeset
|
365 |
return trafficClass; // ipv6 tos |
2 | 366 |
} |
367 |
case SO_KEEPALIVE: |
|
368 |
ret = socketGetOption(opt, null); |
|
369 |
return Boolean.valueOf(ret != -1); |
|
36115 | 370 |
case SO_REUSEPORT: |
371 |
if (!supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { |
|
372 |
throw new UnsupportedOperationException("unsupported option"); |
|
373 |
} |
|
374 |
ret = socketGetOption(opt, null); |
|
375 |
return Boolean.valueOf(ret != -1); |
|
2 | 376 |
// should never get here |
377 |
default: |
|
378 |
return null; |
|
379 |
} |
|
380 |
} |
|
381 |
||
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
382 |
static final ExtendedSocketOptions extendedOptions = |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
383 |
ExtendedSocketOptions.getInstance(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
384 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
385 |
private static final Set<SocketOption<?>> clientSocketOptions = clientSocketOptions(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
386 |
private static final Set<SocketOption<?>> serverSocketOptions = serverSocketOptions(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
387 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
388 |
private static Set<SocketOption<?>> clientSocketOptions() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
389 |
HashSet<SocketOption<?>> options = new HashSet<>(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
390 |
options.add(StandardSocketOptions.SO_KEEPALIVE); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
391 |
options.add(StandardSocketOptions.SO_SNDBUF); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
392 |
options.add(StandardSocketOptions.SO_RCVBUF); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
393 |
options.add(StandardSocketOptions.SO_REUSEADDR); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
394 |
options.add(StandardSocketOptions.SO_LINGER); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
395 |
options.add(StandardSocketOptions.IP_TOS); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
396 |
options.add(StandardSocketOptions.TCP_NODELAY); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
397 |
if (isReusePortAvailable()) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
398 |
options.add(StandardSocketOptions.SO_REUSEPORT); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
399 |
options.addAll(ExtendedSocketOptions.clientSocketOptions()); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
400 |
return Collections.unmodifiableSet(options); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
401 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
402 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
403 |
private static Set<SocketOption<?>> serverSocketOptions() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
404 |
HashSet<SocketOption<?>> options = new HashSet<>(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
405 |
options.add(StandardSocketOptions.SO_RCVBUF); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
406 |
options.add(StandardSocketOptions.SO_REUSEADDR); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
407 |
options.add(StandardSocketOptions.IP_TOS); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
408 |
if (isReusePortAvailable()) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
409 |
options.add(StandardSocketOptions.SO_REUSEPORT); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
410 |
options.addAll(ExtendedSocketOptions.serverSocketOptions()); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
411 |
return Collections.unmodifiableSet(options); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
412 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
413 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
414 |
@Override |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
415 |
protected Set<SocketOption<?>> supportedOptions() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
416 |
if (isServer) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
417 |
return serverSocketOptions; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
418 |
else |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
419 |
return clientSocketOptions; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
420 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
421 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
422 |
@Override |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
423 |
protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
424 |
Objects.requireNonNull(name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
425 |
if (!supportedOptions().contains(name)) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
426 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
427 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
428 |
if (!name.type().isInstance(value)) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
429 |
throw new IllegalArgumentException("Invalid value '" + value + "'"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
430 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
431 |
if (isClosedOrPending()) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
432 |
throw new SocketException("Socket closed"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
433 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
434 |
if (name == StandardSocketOptions.SO_KEEPALIVE) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
435 |
setOption(SocketOptions.SO_KEEPALIVE, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
436 |
} else if (name == StandardSocketOptions.SO_SNDBUF) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
437 |
if (((Integer)value).intValue() < 0) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
438 |
throw new IllegalArgumentException("Invalid send buffer size:" + value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
439 |
setOption(SocketOptions.SO_SNDBUF, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
440 |
} else if (name == StandardSocketOptions.SO_RCVBUF) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
441 |
if (((Integer)value).intValue() < 0) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
442 |
throw new IllegalArgumentException("Invalid recv buffer size:" + value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
443 |
setOption(SocketOptions.SO_RCVBUF, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
444 |
} else if (name == StandardSocketOptions.SO_REUSEADDR) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
445 |
setOption(SocketOptions.SO_REUSEADDR, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
446 |
} else if (name == StandardSocketOptions.SO_REUSEPORT) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
447 |
setOption(SocketOptions.SO_REUSEPORT, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
448 |
} else if (name == StandardSocketOptions.SO_LINGER ) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
449 |
setOption(SocketOptions.SO_LINGER, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
450 |
} else if (name == StandardSocketOptions.IP_TOS) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
451 |
int i = ((Integer)value).intValue(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
452 |
if (i < 0 || i > 255) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
453 |
throw new IllegalArgumentException("Invalid IP_TOS value: " + value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
454 |
setOption(SocketOptions.IP_TOS, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
455 |
} else if (name == StandardSocketOptions.TCP_NODELAY) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
456 |
setOption(SocketOptions.TCP_NODELAY, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
457 |
} else if (extendedOptions.isOptionSupported(name)) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
458 |
extendedOptions.setOption(fd, name, value); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
459 |
} else { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
460 |
throw new AssertionError("unknown option: " + name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
461 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
462 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
463 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
464 |
@Override |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
465 |
@SuppressWarnings("unchecked") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
466 |
protected <T> T getOption(SocketOption<T> name) throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
467 |
Objects.requireNonNull(name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
468 |
if (!supportedOptions().contains(name)) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
469 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
470 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
471 |
if (isClosedOrPending()) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
472 |
throw new SocketException("Socket closed"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
473 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
474 |
if (name == StandardSocketOptions.SO_KEEPALIVE) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
475 |
return (T)getOption(SocketOptions.SO_KEEPALIVE); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
476 |
} else if (name == StandardSocketOptions.SO_SNDBUF) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
477 |
return (T)getOption(SocketOptions.SO_SNDBUF); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
478 |
} else if (name == StandardSocketOptions.SO_RCVBUF) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
479 |
return (T)getOption(SocketOptions.SO_RCVBUF); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
480 |
} else if (name == StandardSocketOptions.SO_REUSEADDR) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
481 |
return (T)getOption(SocketOptions.SO_REUSEADDR); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
482 |
} else if (name == StandardSocketOptions.SO_REUSEPORT) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
483 |
return (T)getOption(SocketOptions.SO_REUSEPORT); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
484 |
} else if (name == StandardSocketOptions.SO_LINGER) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
485 |
return (T)getOption(SocketOptions.SO_LINGER); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
486 |
} else if (name == StandardSocketOptions.IP_TOS) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
487 |
return (T)getOption(SocketOptions.IP_TOS); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
488 |
} else if (name == StandardSocketOptions.TCP_NODELAY) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
489 |
return (T)getOption(SocketOptions.TCP_NODELAY); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
490 |
} else if (extendedOptions.isOptionSupported(name)) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
491 |
return (T) extendedOptions.getOption(fd, name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
492 |
} else { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
493 |
throw new AssertionError("unknown option: " + name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
494 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
495 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54689
diff
changeset
|
496 |
|
2 | 497 |
/** |
498 |
* The workhorse of the connection operation. Tries several times to |
|
499 |
* establish a connection to the given <host, port>. If unsuccessful, |
|
500 |
* throws an IOException indicating what went wrong. |
|
501 |
*/ |
|
502 |
||
503 |
synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { |
|
2446 | 504 |
synchronized (fdLock) { |
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
505 |
if (!closePending && !isBound) { |
2446 | 506 |
NetHooks.beforeTcpConnect(fd, address, port); |
507 |
} |
|
508 |
} |
|
2 | 509 |
try { |
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
510 |
acquireFD(); |
2 | 511 |
try { |
512 |
socketConnect(address, port, timeout); |
|
1335
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
513 |
/* socket may have been closed during poll/select */ |
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
514 |
synchronized (fdLock) { |
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
515 |
if (closePending) { |
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
516 |
throw new SocketException ("Socket closed"); |
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
517 |
} |
79ed7fd4bb49
6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents:
715
diff
changeset
|
518 |
} |
2 | 519 |
} finally { |
520 |
releaseFD(); |
|
521 |
} |
|
522 |
} catch (IOException e) { |
|
523 |
close(); |
|
50722
bc104aaf24e9
8204233: Add configurable option for enhanced socket IOException messages
michaelm
parents:
49249
diff
changeset
|
524 |
throw SocketExceptions.of(e, new InetSocketAddress(address, port)); |
2 | 525 |
} |
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* Binds the socket to the specified address of the specified local port. |
|
530 |
* @param address the address |
|
14014 | 531 |
* @param lport the port |
2 | 532 |
*/ |
533 |
protected synchronized void bind(InetAddress address, int lport) |
|
534 |
throws IOException |
|
535 |
{ |
|
2446 | 536 |
synchronized (fdLock) { |
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
537 |
if (!closePending && !isBound) { |
2446 | 538 |
NetHooks.beforeTcpBind(fd, address, lport); |
539 |
} |
|
540 |
} |
|
2 | 541 |
socketBind(address, lport); |
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
542 |
isBound = true; |
2 | 543 |
} |
544 |
||
545 |
/** |
|
546 |
* Listens, for a specified amount of time, for connections. |
|
547 |
* @param count the amount of time to listen for connections |
|
548 |
*/ |
|
549 |
protected synchronized void listen(int count) throws IOException { |
|
550 |
socketListen(count); |
|
551 |
} |
|
552 |
||
553 |
/** |
|
554 |
* Accepts connections. |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
555 |
* @param si the socket impl |
2 | 556 |
*/ |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
557 |
protected void accept(SocketImpl si) throws IOException { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
558 |
si.fd = new FileDescriptor(); |
7027
d3404b1406d5
6994079: PlainSocketImpl should close the socket if it fails
chegar
parents:
5506
diff
changeset
|
559 |
acquireFD(); |
2 | 560 |
try { |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
561 |
socketAccept(si); |
2 | 562 |
} finally { |
563 |
releaseFD(); |
|
564 |
} |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
565 |
SocketCleanable.register(si.fd); |
2 | 566 |
} |
567 |
||
568 |
/** |
|
569 |
* Gets an InputStream for this socket. |
|
570 |
*/ |
|
571 |
protected synchronized InputStream getInputStream() throws IOException { |
|
14671
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
572 |
synchronized (fdLock) { |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
573 |
if (isClosedOrPending()) |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
574 |
throw new IOException("Socket Closed"); |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
575 |
if (shut_rd) |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
576 |
throw new IOException("Socket input is shutdown"); |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
577 |
if (socketInputStream == null) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
578 |
PrivilegedExceptionAction<SocketInputStream> pa = () -> new SocketInputStream(this); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
579 |
try { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
580 |
socketInputStream = AccessController.doPrivileged(pa); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
581 |
} catch (PrivilegedActionException e) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
582 |
throw (IOException) e.getCause(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
583 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
584 |
} |
2 | 585 |
} |
586 |
return socketInputStream; |
|
587 |
} |
|
588 |
||
589 |
void setInputStream(SocketInputStream in) { |
|
590 |
socketInputStream = in; |
|
591 |
} |
|
592 |
||
593 |
/** |
|
594 |
* Gets an OutputStream for this socket. |
|
595 |
*/ |
|
596 |
protected synchronized OutputStream getOutputStream() throws IOException { |
|
14671
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
597 |
synchronized (fdLock) { |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
598 |
if (isClosedOrPending()) |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
599 |
throw new IOException("Socket Closed"); |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
600 |
if (shut_wr) |
22fad096737b
8003833: Spurious NPE from Socket.getIn/OutputStream
chegar
parents:
14342
diff
changeset
|
601 |
throw new IOException("Socket output is shutdown"); |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
602 |
if (socketOutputStream == null) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
603 |
PrivilegedExceptionAction<SocketOutputStream> pa = () -> new SocketOutputStream(this); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
604 |
try { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
605 |
socketOutputStream = AccessController.doPrivileged(pa); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
606 |
} catch (PrivilegedActionException e) { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
607 |
throw (IOException) e.getCause(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
608 |
} |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
609 |
} |
14173
8a94baea7747
7181793: Socket getOutputStream create streams that cannot be GC'ed until Socket is closed
coffeys
parents:
14014
diff
changeset
|
610 |
} |
8a94baea7747
7181793: Socket getOutputStream create streams that cannot be GC'ed until Socket is closed
coffeys
parents:
14014
diff
changeset
|
611 |
return socketOutputStream; |
2 | 612 |
} |
613 |
||
614 |
void setFileDescriptor(FileDescriptor fd) { |
|
615 |
this.fd = fd; |
|
616 |
} |
|
617 |
||
618 |
void setAddress(InetAddress address) { |
|
619 |
this.address = address; |
|
620 |
} |
|
621 |
||
622 |
void setPort(int port) { |
|
623 |
this.port = port; |
|
624 |
} |
|
625 |
||
626 |
void setLocalPort(int localport) { |
|
627 |
this.localport = localport; |
|
628 |
} |
|
629 |
||
630 |
/** |
|
631 |
* Returns the number of bytes that can be read without blocking. |
|
632 |
*/ |
|
633 |
protected synchronized int available() throws IOException { |
|
634 |
if (isClosedOrPending()) { |
|
635 |
throw new IOException("Stream closed."); |
|
636 |
} |
|
637 |
||
638 |
/* |
|
10421
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9035
diff
changeset
|
639 |
* If connection has been reset or shut down for input, then return 0 |
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9035
diff
changeset
|
640 |
* to indicate there are no buffered bytes. |
2 | 641 |
*/ |
10421
2ee16a0f6df5
7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents:
9035
diff
changeset
|
642 |
if (isConnectionReset() || shut_rd) { |
2 | 643 |
return 0; |
644 |
} |
|
645 |
||
646 |
/* |
|
647 |
* If no bytes available and we were previously notified |
|
648 |
* of a connection reset then we move to the reset state. |
|
649 |
* |
|
650 |
* If are notified of a connection reset then check |
|
651 |
* again if there are bytes buffered on the socket. |
|
652 |
*/ |
|
653 |
int n = 0; |
|
654 |
try { |
|
655 |
n = socketAvailable(); |
|
656 |
} catch (ConnectionResetException exc1) { |
|
49249
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
657 |
setConnectionReset(); |
2 | 658 |
} |
659 |
return n; |
|
660 |
} |
|
661 |
||
662 |
/** |
|
663 |
* Closes the socket. |
|
664 |
*/ |
|
665 |
protected void close() throws IOException { |
|
666 |
synchronized(fdLock) { |
|
667 |
if (fd != null) { |
|
8817
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
668 |
if (!stream) { |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
669 |
ResourceManager.afterUdpClose(); |
5351579c46a9
6981922: DNS cache poisoning by untrusted applets
michaelm
parents:
7668
diff
changeset
|
670 |
} |
2 | 671 |
if (fdUseCount == 0) { |
672 |
if (closePending) { |
|
673 |
return; |
|
674 |
} |
|
675 |
closePending = true; |
|
676 |
/* |
|
677 |
* We close the FileDescriptor in two-steps - first the |
|
678 |
* "pre-close" which closes the socket but doesn't |
|
679 |
* release the underlying file descriptor. This operation |
|
680 |
* may be lengthy due to untransmitted data and a long |
|
681 |
* linger interval. Once the pre-close is done we do the |
|
682 |
* actual socket to release the fd. |
|
683 |
*/ |
|
684 |
try { |
|
685 |
socketPreClose(); |
|
686 |
} finally { |
|
687 |
socketClose(); |
|
688 |
} |
|
689 |
fd = null; |
|
690 |
return; |
|
691 |
} else { |
|
692 |
/* |
|
693 |
* If a thread has acquired the fd and a close |
|
694 |
* isn't pending then use a deferred close. |
|
695 |
* Also decrement fdUseCount to signal the last |
|
696 |
* thread that releases the fd to close it. |
|
697 |
*/ |
|
698 |
if (!closePending) { |
|
699 |
closePending = true; |
|
700 |
fdUseCount--; |
|
701 |
socketPreClose(); |
|
702 |
} |
|
703 |
} |
|
704 |
} |
|
705 |
} |
|
706 |
} |
|
707 |
||
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
708 |
void reset() { |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50722
diff
changeset
|
709 |
throw new InternalError("should not get here"); |
2 | 710 |
} |
711 |
||
712 |
/** |
|
713 |
* Shutdown read-half of the socket connection; |
|
714 |
*/ |
|
715 |
protected void shutdownInput() throws IOException { |
|
716 |
if (fd != null) { |
|
717 |
socketShutdown(SHUT_RD); |
|
718 |
if (socketInputStream != null) { |
|
719 |
socketInputStream.setEOF(true); |
|
720 |
} |
|
721 |
shut_rd = true; |
|
722 |
} |
|
723 |
} |
|
724 |
||
725 |
/** |
|
726 |
* Shutdown write-half of the socket connection; |
|
727 |
*/ |
|
728 |
protected void shutdownOutput() throws IOException { |
|
729 |
if (fd != null) { |
|
730 |
socketShutdown(SHUT_WR); |
|
731 |
shut_wr = true; |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
protected boolean supportsUrgentData () { |
|
736 |
return true; |
|
737 |
} |
|
738 |
||
739 |
protected void sendUrgentData (int data) throws IOException { |
|
740 |
if (fd == null) { |
|
741 |
throw new IOException("Socket Closed"); |
|
742 |
} |
|
743 |
socketSendUrgentData (data); |
|
744 |
} |
|
745 |
||
746 |
/* |
|
747 |
* "Acquires" and returns the FileDescriptor for this impl |
|
748 |
* |
|
749 |
* A corresponding releaseFD is required to "release" the |
|
750 |
* FileDescriptor. |
|
751 |
*/ |
|
752 |
FileDescriptor acquireFD() { |
|
753 |
synchronized (fdLock) { |
|
754 |
fdUseCount++; |
|
755 |
return fd; |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
/* |
|
760 |
* "Release" the FileDescriptor for this impl. |
|
761 |
* |
|
762 |
* If the use count goes to -1 then the socket is closed. |
|
763 |
*/ |
|
764 |
void releaseFD() { |
|
765 |
synchronized (fdLock) { |
|
766 |
fdUseCount--; |
|
767 |
if (fdUseCount == -1) { |
|
768 |
if (fd != null) { |
|
769 |
try { |
|
770 |
socketClose(); |
|
771 |
} catch (IOException e) { |
|
772 |
} finally { |
|
773 |
fd = null; |
|
774 |
} |
|
775 |
} |
|
776 |
} |
|
777 |
} |
|
778 |
} |
|
779 |
||
49249
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
780 |
boolean isConnectionReset() { |
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
781 |
return connectionReset; |
2 | 782 |
} |
783 |
||
49249
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
784 |
void setConnectionReset() { |
92cca24c8807
8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents:
48737
diff
changeset
|
785 |
connectionReset = true; |
2 | 786 |
} |
787 |
||
788 |
/* |
|
789 |
* Return true if already closed or close is pending |
|
790 |
*/ |
|
791 |
public boolean isClosedOrPending() { |
|
792 |
/* |
|
793 |
* Lock on fdLock to ensure that we wait if a |
|
794 |
* close is in progress. |
|
795 |
*/ |
|
796 |
synchronized (fdLock) { |
|
797 |
if (closePending || (fd == null)) { |
|
798 |
return true; |
|
799 |
} else { |
|
800 |
return false; |
|
801 |
} |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
/* |
|
806 |
* Return the current value of SO_TIMEOUT |
|
807 |
*/ |
|
808 |
public int getTimeout() { |
|
809 |
return timeout; |
|
810 |
} |
|
811 |
||
812 |
/* |
|
813 |
* "Pre-close" a socket by dup'ing the file descriptor - this enables |
|
814 |
* the socket to be closed without releasing the file descriptor. |
|
815 |
*/ |
|
816 |
private void socketPreClose() throws IOException { |
|
817 |
socketClose0(true); |
|
818 |
} |
|
819 |
||
820 |
/* |
|
821 |
* Close the socket (and release the file descriptor). |
|
822 |
*/ |
|
823 |
protected void socketClose() throws IOException { |
|
48737
7c12219870fd
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
rriggs
parents:
47216
diff
changeset
|
824 |
SocketCleanable.unregister(fd); |
2 | 825 |
socketClose0(false); |
826 |
} |
|
827 |
||
54689
b28b7f631301
8216978: Drop support for pre JDK 1.4 SocketImpl implementations
michaelm
parents:
54155
diff
changeset
|
828 |
abstract void socketCreate(boolean stream) throws IOException; |
2 | 829 |
abstract void socketConnect(InetAddress address, int port, int timeout) |
830 |
throws IOException; |
|
831 |
abstract void socketBind(InetAddress address, int port) |
|
832 |
throws IOException; |
|
833 |
abstract void socketListen(int count) |
|
834 |
throws IOException; |
|
835 |
abstract void socketAccept(SocketImpl s) |
|
836 |
throws IOException; |
|
837 |
abstract int socketAvailable() |
|
838 |
throws IOException; |
|
839 |
abstract void socketClose0(boolean useDeferredClose) |
|
840 |
throws IOException; |
|
841 |
abstract void socketShutdown(int howto) |
|
842 |
throws IOException; |
|
843 |
abstract void socketSetOption(int cmd, boolean on, Object value) |
|
844 |
throws SocketException; |
|
845 |
abstract int socketGetOption(int opt, Object iaContainerObj) throws SocketException; |
|
846 |
abstract void socketSendUrgentData(int data) |
|
847 |
throws IOException; |
|
848 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30963
diff
changeset
|
849 |
public static final int SHUT_RD = 0; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30963
diff
changeset
|
850 |
public static final int SHUT_WR = 1; |
36115 | 851 |
|
852 |
private static native boolean isReusePortAvailable0(); |
|
2 | 853 |
} |