Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/java/net/PlainSocketImpl.java
32287 views
1
/*
2
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
package java.net;
26
27
import java.io.*;
28
import java.security.PrivilegedAction;
29
30
/*
31
* This class PlainSocketImpl simply delegates to the appropriate real
32
* SocketImpl. We do this because PlainSocketImpl is already extended
33
* by SocksSocketImpl.
34
* <p>
35
* There are two possibilities for the real SocketImpl,
36
* TwoStacksPlainSocketImpl or DualStackPlainSocketImpl. We use
37
* DualStackPlainSocketImpl on systems that have a dual stack
38
* TCP implementation. Otherwise we create an instance of
39
* TwoStacksPlainSocketImpl and delegate to it.
40
*
41
* @author Chris Hegarty
42
*/
43
44
class PlainSocketImpl extends AbstractPlainSocketImpl
45
{
46
private AbstractPlainSocketImpl impl;
47
48
/* the windows version. */
49
private static float version;
50
51
/* java.net.preferIPv4Stack */
52
private static boolean preferIPv4Stack = false;
53
54
/* If the version supports a dual stack TCP implementation */
55
private static boolean useDualStackImpl = false;
56
57
/* sun.net.useExclusiveBind */
58
private static String exclBindProp;
59
60
/* True if exclusive binding is on for Windows */
61
private static boolean exclusiveBind = true;
62
63
static {
64
java.security.AccessController.doPrivileged( new PrivilegedAction<Object>() {
65
public Object run() {
66
version = 0;
67
try {
68
version = Float.parseFloat(System.getProperties().getProperty("os.version"));
69
preferIPv4Stack = Boolean.parseBoolean(
70
System.getProperties().getProperty("java.net.preferIPv4Stack"));
71
exclBindProp = System.getProperty("sun.net.useExclusiveBind");
72
} catch (NumberFormatException e ) {
73
assert false : e;
74
}
75
return null; // nothing to return
76
} });
77
78
// (version >= 6.0) implies Vista or greater.
79
if (version >= 6.0 && !preferIPv4Stack) {
80
useDualStackImpl = true;
81
}
82
83
if (exclBindProp != null) {
84
// sun.net.useExclusiveBind is true
85
exclusiveBind = exclBindProp.length() == 0 ? true
86
: Boolean.parseBoolean(exclBindProp);
87
} else if (version < 6.0) {
88
exclusiveBind = false;
89
}
90
}
91
92
/**
93
* Constructs an empty instance.
94
*/
95
PlainSocketImpl() {
96
if (useDualStackImpl) {
97
impl = new DualStackPlainSocketImpl(exclusiveBind);
98
} else {
99
impl = new TwoStacksPlainSocketImpl(exclusiveBind);
100
}
101
}
102
103
/**
104
* Constructs an instance with the given file descriptor.
105
*/
106
PlainSocketImpl(FileDescriptor fd) {
107
if (useDualStackImpl) {
108
impl = new DualStackPlainSocketImpl(fd, exclusiveBind);
109
} else {
110
impl = new TwoStacksPlainSocketImpl(fd, exclusiveBind);
111
}
112
}
113
114
// Override methods in SocketImpl that access impl's fields.
115
116
protected FileDescriptor getFileDescriptor() {
117
return impl.getFileDescriptor();
118
}
119
120
protected InetAddress getInetAddress() {
121
return impl.getInetAddress();
122
}
123
124
protected int getPort() {
125
return impl.getPort();
126
}
127
128
protected int getLocalPort() {
129
return impl.getLocalPort();
130
}
131
132
void setSocket(Socket soc) {
133
impl.setSocket(soc);
134
}
135
136
Socket getSocket() {
137
return impl.getSocket();
138
}
139
140
void setServerSocket(ServerSocket soc) {
141
impl.setServerSocket(soc);
142
}
143
144
ServerSocket getServerSocket() {
145
return impl.getServerSocket();
146
}
147
148
public String toString() {
149
return impl.toString();
150
}
151
152
// Override methods in AbstractPlainSocketImpl that access impl's fields.
153
154
protected synchronized void create(boolean stream) throws IOException {
155
impl.create(stream);
156
157
// set fd to delegate's fd to be compatible with older releases
158
this.fd = impl.fd;
159
}
160
161
protected void connect(String host, int port)
162
throws UnknownHostException, IOException
163
{
164
impl.connect(host, port);
165
}
166
167
protected void connect(InetAddress address, int port) throws IOException {
168
impl.connect(address, port);
169
}
170
171
protected void connect(SocketAddress address, int timeout) throws IOException {
172
impl.connect(address, timeout);
173
}
174
175
public void setOption(int opt, Object val) throws SocketException {
176
impl.setOption(opt, val);
177
}
178
179
public Object getOption(int opt) throws SocketException {
180
return impl.getOption(opt);
181
}
182
183
synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException {
184
impl.doConnect(address, port, timeout);
185
}
186
187
protected synchronized void bind(InetAddress address, int lport)
188
throws IOException
189
{
190
impl.bind(address, lport);
191
}
192
193
protected synchronized void accept(SocketImpl s) throws IOException {
194
if (s instanceof PlainSocketImpl) {
195
// pass in the real impl not the wrapper.
196
SocketImpl delegate = ((PlainSocketImpl)s).impl;
197
delegate.address = new InetAddress();
198
delegate.fd = new FileDescriptor();
199
impl.accept(delegate);
200
// set fd to delegate's fd to be compatible with older releases
201
s.fd = delegate.fd;
202
} else {
203
impl.accept(s);
204
}
205
}
206
207
void setFileDescriptor(FileDescriptor fd) {
208
impl.setFileDescriptor(fd);
209
}
210
211
void setAddress(InetAddress address) {
212
impl.setAddress(address);
213
}
214
215
void setPort(int port) {
216
impl.setPort(port);
217
}
218
219
void setLocalPort(int localPort) {
220
impl.setLocalPort(localPort);
221
}
222
223
protected synchronized InputStream getInputStream() throws IOException {
224
return impl.getInputStream();
225
}
226
227
void setInputStream(SocketInputStream in) {
228
impl.setInputStream(in);
229
}
230
231
protected synchronized OutputStream getOutputStream() throws IOException {
232
return impl.getOutputStream();
233
}
234
235
protected void close() throws IOException {
236
try {
237
impl.close();
238
} finally {
239
// set fd to delegate's fd to be compatible with older releases
240
this.fd = null;
241
}
242
}
243
244
void reset() throws IOException {
245
try {
246
impl.reset();
247
} finally {
248
// set fd to delegate's fd to be compatible with older releases
249
this.fd = null;
250
}
251
}
252
253
protected void shutdownInput() throws IOException {
254
impl.shutdownInput();
255
}
256
257
protected void shutdownOutput() throws IOException {
258
impl.shutdownOutput();
259
}
260
261
protected void sendUrgentData(int data) throws IOException {
262
impl.sendUrgentData(data);
263
}
264
265
FileDescriptor acquireFD() {
266
return impl.acquireFD();
267
}
268
269
void releaseFD() {
270
impl.releaseFD();
271
}
272
273
public boolean isConnectionReset() {
274
return impl.isConnectionReset();
275
}
276
277
public boolean isConnectionResetPending() {
278
return impl.isConnectionResetPending();
279
}
280
281
public void setConnectionReset() {
282
impl.setConnectionReset();
283
}
284
285
public void setConnectionResetPending() {
286
impl.setConnectionResetPending();
287
}
288
289
public boolean isClosedOrPending() {
290
return impl.isClosedOrPending();
291
}
292
293
public int getTimeout() {
294
return impl.getTimeout();
295
}
296
297
// Override methods in AbstractPlainSocketImpl that need to be implemented.
298
299
void socketCreate(boolean isServer) throws IOException {
300
impl.socketCreate(isServer);
301
}
302
303
void socketConnect(InetAddress address, int port, int timeout)
304
throws IOException {
305
impl.socketConnect(address, port, timeout);
306
}
307
308
void socketBind(InetAddress address, int port)
309
throws IOException {
310
impl.socketBind(address, port);
311
}
312
313
void socketListen(int count) throws IOException {
314
impl.socketListen(count);
315
}
316
317
void socketAccept(SocketImpl s) throws IOException {
318
impl.socketAccept(s);
319
}
320
321
int socketAvailable() throws IOException {
322
return impl.socketAvailable();
323
}
324
325
void socketClose0(boolean useDeferredClose) throws IOException {
326
impl.socketClose0(useDeferredClose);
327
}
328
329
void socketShutdown(int howto) throws IOException {
330
impl.socketShutdown(howto);
331
}
332
333
void socketSetOption(int cmd, boolean on, Object value)
334
throws SocketException {
335
impl.socketSetOption(cmd, on, value);
336
}
337
338
int socketGetOption(int opt, Object iaContainerObj) throws SocketException {
339
return impl.socketGetOption(opt, iaContainerObj);
340
}
341
342
void socketSendUrgentData(int data) throws IOException {
343
impl.socketSendUrgentData(data);
344
}
345
}
346
347