Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/java/net/PlainSocketImpl.java
32285 views
1
/*
2
* Copyright (c) 2007, 2008, 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.IOException;
28
import java.io.FileDescriptor;
29
import java.util.Set;
30
import java.util.HashSet;
31
import java.util.Collections;
32
import jdk.net.*;
33
34
import sun.net.ExtendedOptionsImpl;
35
36
/*
37
* On Unix systems we simply delegate to native methods.
38
*
39
* @author Chris Hegarty
40
*/
41
42
class PlainSocketImpl extends AbstractPlainSocketImpl
43
{
44
static {
45
initProto();
46
}
47
48
/**
49
* Constructs an empty instance.
50
*/
51
PlainSocketImpl() { }
52
53
/**
54
* Constructs an instance with the given file descriptor.
55
*/
56
PlainSocketImpl(FileDescriptor fd) {
57
this.fd = fd;
58
}
59
60
protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
61
if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
62
checkSetOption(name, value, SocketFlow.class);
63
ExtendedOptionsImpl.setFlowOption(getFileDescriptor(), (SocketFlow)value);
64
} else if (name == ExtendedSocketOptions.TCP_KEEPIDLE) {
65
checkSetOption(name, value, Integer.class);
66
ExtendedOptionsImpl.setTcpKeepAliveTime(getFileDescriptor(), (Integer)value);
67
} else if (name == ExtendedSocketOptions.TCP_KEEPINTERVAL) {
68
checkSetOption(name, value, Integer.class);
69
ExtendedOptionsImpl.setTcpKeepAliveIntvl(getFileDescriptor(), (Integer)value);
70
} else if (name == ExtendedSocketOptions.TCP_KEEPCOUNT) {
71
checkSetOption(name, value, Integer.class);
72
ExtendedOptionsImpl.setTcpKeepAliveProbes(getFileDescriptor(), (Integer)value);
73
} else {
74
super.setOption(name, value);
75
}
76
}
77
78
private <T> void checkSetOption(SocketOption<T> name, T value, Class<?> expected) throws IOException {
79
if (isClosedOrPending()) {
80
throw new SocketException("Socket closed");
81
}
82
ExtendedOptionsImpl.checkSetOptionPermission(name);
83
ExtendedOptionsImpl.checkValueType(value, expected);
84
}
85
86
private <T> void checkGetOption(SocketOption<T> name) throws IOException {
87
if (isClosedOrPending()) {
88
throw new SocketException("Socket closed");
89
}
90
ExtendedOptionsImpl.checkGetOptionPermission(name);
91
}
92
93
protected <T> T getOption(SocketOption<T> name) throws IOException {
94
if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
95
checkGetOption(name);
96
SocketFlow flow = SocketFlow.create();
97
ExtendedOptionsImpl.getFlowOption(getFileDescriptor(), flow);
98
return (T)flow;
99
} else if (name == ExtendedSocketOptions.TCP_KEEPIDLE) {
100
checkGetOption(name);
101
int retVal = ExtendedOptionsImpl.getTcpKeepAliveTime(getFileDescriptor());
102
return (T)Integer.valueOf(retVal);
103
} else if (name == ExtendedSocketOptions.TCP_KEEPINTERVAL) {
104
checkGetOption(name);
105
int retVal = ExtendedOptionsImpl.getTcpKeepAliveIntvl(getFileDescriptor());
106
return (T)Integer.valueOf(retVal);
107
} else if (name == ExtendedSocketOptions.TCP_KEEPCOUNT) {
108
checkGetOption(name);
109
int retVal = ExtendedOptionsImpl.getTcpKeepAliveProbes(getFileDescriptor());
110
return (T)Integer.valueOf(retVal);
111
} else {
112
return super.getOption(name);
113
}
114
}
115
116
protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
117
try {
118
socketSetOption0(opt, b, val);
119
} catch (SocketException se) {
120
if (socket == null || !socket.isConnected())
121
throw se;
122
}
123
}
124
125
native void socketCreate(boolean isServer) throws IOException;
126
127
native void socketConnect(InetAddress address, int port, int timeout)
128
throws IOException;
129
130
native void socketBind(InetAddress address, int port)
131
throws IOException;
132
133
native void socketListen(int count) throws IOException;
134
135
native void socketAccept(SocketImpl s) throws IOException;
136
137
native int socketAvailable() throws IOException;
138
139
native void socketClose0(boolean useDeferredClose) throws IOException;
140
141
native void socketShutdown(int howto) throws IOException;
142
143
static native void initProto();
144
145
native void socketSetOption0(int cmd, boolean on, Object value)
146
throws SocketException;
147
148
native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
149
150
native void socketSendUrgentData(int data) throws IOException;
151
}
152
153