author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58242 | 94bb65cb37d3 |
child 58680 | 7e9e2f10a050 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1996, 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.FileDescriptor; |
|
29 |
import java.io.IOException; |
|
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
30 |
import java.util.Objects; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
31 |
import java.util.Set; |
2 | 32 |
|
33 |
/** |
|
34 |
* Abstract datagram and multicast socket implementation base class. |
|
35 |
* @author Pavani Diwanji |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24046
diff
changeset
|
36 |
* @since 1.1 |
2 | 37 |
*/ |
38 |
||
39 |
public abstract class DatagramSocketImpl implements SocketOptions { |
|
40 |
||
41 |
/** |
|
42 |
* The local port number. |
|
43 |
*/ |
|
44 |
protected int localPort; |
|
45 |
||
46 |
/** |
|
47 |
* The file descriptor object. |
|
48 |
*/ |
|
49 |
protected FileDescriptor fd; |
|
50 |
||
51 |
/** |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
52 |
* The DatagramSocket or MulticastSocket |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
53 |
* that owns this impl |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
54 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
55 |
DatagramSocket socket; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
56 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
57 |
void setDatagramSocket(DatagramSocket socket) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
58 |
this.socket = socket; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
59 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
60 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
61 |
DatagramSocket getDatagramSocket() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
62 |
return socket; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
63 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
64 |
|
27078 | 65 |
int dataAvailable() { |
66 |
// default impl returns zero, which disables the calling |
|
67 |
// functionality |
|
68 |
return 0; |
|
69 |
} |
|
70 |
||
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
71 |
/** |
2 | 72 |
* Creates a datagram socket. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
73 |
* @throws SocketException if there is an error in the |
2 | 74 |
* underlying protocol, such as a TCP error. |
75 |
*/ |
|
76 |
protected abstract void create() throws SocketException; |
|
77 |
||
78 |
/** |
|
79 |
* Binds a datagram socket to a local port and address. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
80 |
* @param lport the local port |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
81 |
* @param laddr the local address |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
82 |
* @throws SocketException if there is an error in the |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
83 |
* underlying protocol, such as a TCP error. |
2 | 84 |
*/ |
85 |
protected abstract void bind(int lport, InetAddress laddr) throws SocketException; |
|
86 |
||
87 |
/** |
|
88 |
* Sends a datagram packet. The packet contains the data and the |
|
89 |
* destination address to send the packet to. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
90 |
* @param p the packet to be sent. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
91 |
* @throws IOException if an I/O exception occurs while sending the |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
92 |
* datagram packet. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
93 |
* @throws PortUnreachableException may be thrown if the socket is connected |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
94 |
* to a currently unreachable destination. Note, there is no guarantee that |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
95 |
* the exception will be thrown. |
2 | 96 |
*/ |
97 |
protected abstract void send(DatagramPacket p) throws IOException; |
|
98 |
||
99 |
/** |
|
100 |
* Connects a datagram socket to a remote destination. This associates the remote |
|
101 |
* address with the local socket so that datagrams may only be sent to this destination |
|
102 |
* and received from this destination. This may be overridden to call a native |
|
103 |
* system connect. |
|
104 |
* |
|
105 |
* <p>If the remote destination to which the socket is connected does not |
|
106 |
* exist, or is otherwise unreachable, and if an ICMP destination unreachable |
|
107 |
* packet has been received for that address, then a subsequent call to |
|
108 |
* send or receive may throw a PortUnreachableException. |
|
109 |
* Note, there is no guarantee that the exception will be thrown. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
110 |
* @param address the remote InetAddress to connect to |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
111 |
* @param port the remote port number |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
112 |
* @throws SocketException may be thrown if the socket cannot be |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
113 |
* connected to the remote destination |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
114 |
* @since 1.4 |
2 | 115 |
*/ |
116 |
protected void connect(InetAddress address, int port) throws SocketException {} |
|
117 |
||
118 |
/** |
|
119 |
* Disconnects a datagram socket from its remote destination. |
|
120 |
* @since 1.4 |
|
121 |
*/ |
|
122 |
protected void disconnect() {} |
|
123 |
||
124 |
/** |
|
19069 | 125 |
* Peek at the packet to see who it is from. Updates the specified {@code InetAddress} |
2 | 126 |
* to the address which the packet came from. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
127 |
* @param i an InetAddress object |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
128 |
* @return the port number which the packet came from. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
129 |
* @throws IOException if an I/O exception occurs |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
130 |
* @throws PortUnreachableException may be thrown if the socket is connected |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
131 |
* to a currently unreachable destination. Note, there is no guarantee that the |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
132 |
* exception will be thrown. |
2 | 133 |
*/ |
134 |
protected abstract int peek(InetAddress i) throws IOException; |
|
135 |
||
136 |
/** |
|
137 |
* Peek at the packet to see who it is from. The data is copied into the specified |
|
19069 | 138 |
* {@code DatagramPacket}. The data is returned, |
2 | 139 |
* but not consumed, so that a subsequent peekData/receive operation |
140 |
* will see the same data. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
141 |
* @param p the Packet Received. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
142 |
* @return the port number which the packet came from. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
143 |
* @throws IOException if an I/O exception occurs |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
144 |
* @throws PortUnreachableException may be thrown if the socket is connected |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
145 |
* to a currently unreachable destination. Note, there is no guarantee that the |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
146 |
* exception will be thrown. |
2 | 147 |
* @since 1.4 |
148 |
*/ |
|
149 |
protected abstract int peekData(DatagramPacket p) throws IOException; |
|
150 |
/** |
|
151 |
* Receive the datagram packet. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
152 |
* @param p the Packet Received. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
153 |
* @throws IOException if an I/O exception occurs |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
154 |
* while receiving the datagram packet. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
155 |
* @throws PortUnreachableException may be thrown if the socket is connected |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
156 |
* to a currently unreachable destination. Note, there is no guarantee that the |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
157 |
* exception will be thrown. |
2 | 158 |
*/ |
159 |
protected abstract void receive(DatagramPacket p) throws IOException; |
|
160 |
||
161 |
/** |
|
162 |
* Set the TTL (time-to-live) option. |
|
163 |
* @param ttl a byte specifying the TTL value |
|
164 |
* |
|
165 |
* @deprecated use setTimeToLive instead. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
166 |
* @throws IOException if an I/O exception occurs while setting |
2 | 167 |
* the time-to-live option. |
168 |
* @see #getTTL() |
|
169 |
*/ |
|
170 |
@Deprecated |
|
171 |
protected abstract void setTTL(byte ttl) throws IOException; |
|
172 |
||
173 |
/** |
|
174 |
* Retrieve the TTL (time-to-live) option. |
|
175 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
176 |
* @throws IOException if an I/O exception occurs |
2 | 177 |
* while retrieving the time-to-live option |
178 |
* @deprecated use getTimeToLive instead. |
|
179 |
* @return a byte representing the TTL value |
|
180 |
* @see #setTTL(byte) |
|
181 |
*/ |
|
182 |
@Deprecated |
|
183 |
protected abstract byte getTTL() throws IOException; |
|
184 |
||
185 |
/** |
|
186 |
* Set the TTL (time-to-live) option. |
|
19069 | 187 |
* @param ttl an {@code int} specifying the time-to-live value |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
188 |
* @throws IOException if an I/O exception occurs |
2 | 189 |
* while setting the time-to-live option. |
190 |
* @see #getTimeToLive() |
|
191 |
*/ |
|
192 |
protected abstract void setTimeToLive(int ttl) throws IOException; |
|
193 |
||
194 |
/** |
|
195 |
* Retrieve the TTL (time-to-live) option. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
196 |
* @throws IOException if an I/O exception occurs |
2 | 197 |
* while retrieving the time-to-live option |
19069 | 198 |
* @return an {@code int} representing the time-to-live value |
2 | 199 |
* @see #setTimeToLive(int) |
200 |
*/ |
|
201 |
protected abstract int getTimeToLive() throws IOException; |
|
202 |
||
203 |
/** |
|
204 |
* Join the multicast group. |
|
205 |
* @param inetaddr multicast address to join. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
206 |
* @throws IOException if an I/O exception occurs |
2 | 207 |
* while joining the multicast group. |
208 |
*/ |
|
209 |
protected abstract void join(InetAddress inetaddr) throws IOException; |
|
210 |
||
211 |
/** |
|
212 |
* Leave the multicast group. |
|
213 |
* @param inetaddr multicast address to leave. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
214 |
* @throws IOException if an I/O exception occurs |
2 | 215 |
* while leaving the multicast group. |
216 |
*/ |
|
217 |
protected abstract void leave(InetAddress inetaddr) throws IOException; |
|
218 |
||
219 |
/** |
|
220 |
* Join the multicast group. |
|
221 |
* @param mcastaddr address to join. |
|
222 |
* @param netIf specifies the local interface to receive multicast |
|
223 |
* datagram packets |
|
224 |
* @throws IOException if an I/O exception occurs while joining |
|
225 |
* the multicast group |
|
226 |
* @since 1.4 |
|
227 |
*/ |
|
228 |
protected abstract void joinGroup(SocketAddress mcastaddr, |
|
229 |
NetworkInterface netIf) |
|
230 |
throws IOException; |
|
231 |
||
232 |
/** |
|
233 |
* Leave the multicast group. |
|
234 |
* @param mcastaddr address to leave. |
|
235 |
* @param netIf specified the local interface to leave the group at |
|
236 |
* @throws IOException if an I/O exception occurs while leaving |
|
237 |
* the multicast group |
|
238 |
* @since 1.4 |
|
239 |
*/ |
|
240 |
protected abstract void leaveGroup(SocketAddress mcastaddr, |
|
241 |
NetworkInterface netIf) |
|
242 |
throws IOException; |
|
243 |
||
244 |
/** |
|
245 |
* Close the socket. |
|
246 |
*/ |
|
247 |
protected abstract void close(); |
|
248 |
||
249 |
/** |
|
250 |
* Gets the local port. |
|
19069 | 251 |
* @return an {@code int} representing the local port value |
2 | 252 |
*/ |
253 |
protected int getLocalPort() { |
|
254 |
return localPort; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Gets the datagram socket file descriptor. |
|
19069 | 259 |
* @return a {@code FileDescriptor} object representing the datagram socket |
2 | 260 |
* file descriptor |
261 |
*/ |
|
262 |
protected FileDescriptor getFileDescriptor() { |
|
263 |
return fd; |
|
264 |
} |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
265 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
266 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
267 |
* Called to set a socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
268 |
* |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
269 |
* @implSpec |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
270 |
* The default implementation of this method first checks that the given |
55500 | 271 |
* socket option {@code name} is not null, then throws {@code |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
272 |
* UnsupportedOperationException}. Subclasses should override this method |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
273 |
* with an appropriate implementation. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
274 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
275 |
* @param <T> The type of the socket option value |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
276 |
* @param name The socket option |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
277 |
* @param value The value of the socket option. A value of {@code null} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
278 |
* may be valid for some options. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
279 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
280 |
* @throws UnsupportedOperationException if the DatagramSocketImpl does not |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
281 |
* support the option |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
282 |
* @throws IllegalArgumentException if the value is not valid for |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
283 |
* the option |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
284 |
* @throws IOException if an I/O error occurs, or if the socket is closed |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
285 |
* @throws NullPointerException if name is {@code null} |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
286 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
28852
diff
changeset
|
287 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
288 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
289 |
protected <T> void setOption(SocketOption<T> name, T value) throws IOException { |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
290 |
Objects.requireNonNull(name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
291 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
292 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
293 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
294 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
295 |
* Called to get a socket option. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
296 |
* |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
297 |
* @implSpec |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
298 |
* The default implementation of this method first checks that the given |
55500 | 299 |
* socket option {@code name} is not null, then throws {@code |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
300 |
* UnsupportedOperationException}. Subclasses should override this method |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
301 |
* with an appropriate implementation. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
302 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
303 |
* @param <T> The type of the socket option value |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
55500
diff
changeset
|
304 |
* @param name The socket option |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
305 |
* @return the socket option |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
306 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
307 |
* @throws UnsupportedOperationException if the DatagramSocketImpl does not |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
308 |
* support the option |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
309 |
* @throws IOException if an I/O error occurs, or if the socket is closed |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
310 |
* @throws NullPointerException if name is {@code null} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
311 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
28852
diff
changeset
|
312 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
313 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
314 |
protected <T> T getOption(SocketOption<T> name) throws IOException { |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
315 |
Objects.requireNonNull(name); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
316 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
36228
a16a22218e23
8148609: socket impl supportedOptions() should return an immutable set
vtewari
parents:
36115
diff
changeset
|
317 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
318 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
319 |
/** |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
320 |
* Returns a set of SocketOptions supported by this impl |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
321 |
* and by this impl's socket (DatagramSocket or MulticastSocket) |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
322 |
* |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
323 |
* @implSpec |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
324 |
* The default implementation of this method returns an empty set. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
325 |
* Subclasses should override this method with an appropriate implementation. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
326 |
* |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
327 |
* @return a Set of SocketOptions |
36228
a16a22218e23
8148609: socket impl supportedOptions() should return an immutable set
vtewari
parents:
36115
diff
changeset
|
328 |
* |
a16a22218e23
8148609: socket impl supportedOptions() should return an immutable set
vtewari
parents:
36115
diff
changeset
|
329 |
* @since 9 |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
330 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
331 |
protected Set<SocketOption<?>> supportedOptions() { |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
47216
diff
changeset
|
332 |
return Set.of(); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
19069
diff
changeset
|
333 |
} |
2 | 334 |
} |