1 /*
2 * Copyright (c) 2014, 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
236 * socket type from the java.net package.
237 */
238 public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) {
239 Set<SocketOption<?>> set = options.get(socketType);
240 if (set == null) {
241 throw new IllegalArgumentException("unknown socket type");
242 }
243 return set;
244 }
245
246 private static void checkValueType(Object value, Class<?> type) {
247 if (!type.isAssignableFrom(value.getClass())) {
248 String s = "Found: " + value.getClass().toString() + " Expected: "
249 + type.toString();
250 throw new IllegalArgumentException(s);
251 }
252 }
253
254 private static void initOptionSets() {
255 boolean flowsupported = ExtendedOptionsImpl.flowSupported();
256
257 // Socket
258
259 Set<SocketOption<?>> set = new HashSet<>();
260 set.add(StandardSocketOptions.SO_KEEPALIVE);
261 set.add(StandardSocketOptions.SO_SNDBUF);
262 set.add(StandardSocketOptions.SO_RCVBUF);
263 set.add(StandardSocketOptions.SO_REUSEADDR);
264 set.add(StandardSocketOptions.SO_LINGER);
265 set.add(StandardSocketOptions.IP_TOS);
266 set.add(StandardSocketOptions.TCP_NODELAY);
267 if (flowsupported) {
268 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
269 }
270 set = Collections.unmodifiableSet(set);
271 options.put(Socket.class, set);
272
273 // ServerSocket
274
275 set = new HashSet<>();
276 set.add(StandardSocketOptions.SO_RCVBUF);
277 set.add(StandardSocketOptions.SO_REUSEADDR);
278 set.add(StandardSocketOptions.IP_TOS);
279 set = Collections.unmodifiableSet(set);
280 options.put(ServerSocket.class, set);
281
282 // DatagramSocket
283
284 set = new HashSet<>();
285 set.add(StandardSocketOptions.SO_SNDBUF);
286 set.add(StandardSocketOptions.SO_RCVBUF);
287 set.add(StandardSocketOptions.SO_REUSEADDR);
288 set.add(StandardSocketOptions.IP_TOS);
289 if (flowsupported) {
290 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
291 }
292 set = Collections.unmodifiableSet(set);
293 options.put(DatagramSocket.class, set);
294
295 // MulticastSocket
296
297 set = new HashSet<>();
298 set.add(StandardSocketOptions.SO_SNDBUF);
299 set.add(StandardSocketOptions.SO_RCVBUF);
300 set.add(StandardSocketOptions.SO_REUSEADDR);
301 set.add(StandardSocketOptions.IP_TOS);
302 set.add(StandardSocketOptions.IP_MULTICAST_IF);
303 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
304 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
305 if (flowsupported) {
306 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
307 }
308 set = Collections.unmodifiableSet(set);
309 options.put(MulticastSocket.class, set);
310 }
311 }
|
1 /*
2 * Copyright (c) 2014, 2016, 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
236 * socket type from the java.net package.
237 */
238 public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) {
239 Set<SocketOption<?>> set = options.get(socketType);
240 if (set == null) {
241 throw new IllegalArgumentException("unknown socket type");
242 }
243 return set;
244 }
245
246 private static void checkValueType(Object value, Class<?> type) {
247 if (!type.isAssignableFrom(value.getClass())) {
248 String s = "Found: " + value.getClass().toString() + " Expected: "
249 + type.toString();
250 throw new IllegalArgumentException(s);
251 }
252 }
253
254 private static void initOptionSets() {
255 boolean flowsupported = ExtendedOptionsImpl.flowSupported();
256 boolean quickAckSupported = ExtendedOptionsImpl.isQuickAckAvailable();
257
258 // Socket
259
260 Set<SocketOption<?>> set = new HashSet<>();
261 set.add(StandardSocketOptions.SO_KEEPALIVE);
262 set.add(StandardSocketOptions.SO_SNDBUF);
263 set.add(StandardSocketOptions.SO_RCVBUF);
264 set.add(StandardSocketOptions.SO_REUSEADDR);
265 set.add(StandardSocketOptions.SO_LINGER);
266 set.add(StandardSocketOptions.IP_TOS);
267 set.add(StandardSocketOptions.TCP_NODELAY);
268 if (flowsupported) {
269 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
270 }
271 if (quickAckSupported) {
272 set.add(ExtendedSocketOptions.SO_QUICKACK);
273 }
274 set = Collections.unmodifiableSet(set);
275 options.put(Socket.class, set);
276
277 // ServerSocket
278
279 set = new HashSet<>();
280 set.add(StandardSocketOptions.SO_RCVBUF);
281 set.add(StandardSocketOptions.SO_REUSEADDR);
282 set.add(StandardSocketOptions.IP_TOS);
283 set = Collections.unmodifiableSet(set);
284 options.put(ServerSocket.class, set);
285
286 // DatagramSocket
287
288 set = new HashSet<>();
289 set.add(StandardSocketOptions.SO_SNDBUF);
290 set.add(StandardSocketOptions.SO_RCVBUF);
291 set.add(StandardSocketOptions.SO_REUSEADDR);
292 set.add(StandardSocketOptions.IP_TOS);
293 if (flowsupported) {
294 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
295 }
296 if (quickAckSupported) {
297 set.add(ExtendedSocketOptions.SO_QUICKACK);
298 }
299 set = Collections.unmodifiableSet(set);
300 options.put(DatagramSocket.class, set);
301
302 // MulticastSocket
303
304 set = new HashSet<>();
305 set.add(StandardSocketOptions.SO_SNDBUF);
306 set.add(StandardSocketOptions.SO_RCVBUF);
307 set.add(StandardSocketOptions.SO_REUSEADDR);
308 set.add(StandardSocketOptions.IP_TOS);
309 set.add(StandardSocketOptions.IP_MULTICAST_IF);
310 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
311 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
312 if (flowsupported) {
313 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
314 }
315 if (quickAckSupported) {
316 set.add(ExtendedSocketOptions.SO_QUICKACK);
317 }
318 set = Collections.unmodifiableSet(set);
319 options.put(MulticastSocket.class, set);
320 }
321 }
|