1 /*
2 * Copyright (c) 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
262 private static Map<Class<?>,Set<SocketOption<?>>> optionSets() {
263 Map<Class<?>,Set<SocketOption<?>>> options = new HashMap<>();
264 boolean flowsupported = PlatformSocketOptions.get().flowSupported();
265 boolean reuseportsupported = isReusePortAvailable();
266 // Socket
267
268 Set<SocketOption<?>> set = new HashSet<>();
269 set.add(StandardSocketOptions.SO_KEEPALIVE);
270 set.add(StandardSocketOptions.SO_SNDBUF);
271 set.add(StandardSocketOptions.SO_RCVBUF);
272 set.add(StandardSocketOptions.SO_REUSEADDR);
273 if (reuseportsupported) {
274 set.add(StandardSocketOptions.SO_REUSEPORT);
275 }
276 set.add(StandardSocketOptions.SO_LINGER);
277 set.add(StandardSocketOptions.IP_TOS);
278 set.add(StandardSocketOptions.TCP_NODELAY);
279 if (flowsupported) {
280 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
281 }
282 set = Collections.unmodifiableSet(set);
283 options.put(Socket.class, set);
284
285 // ServerSocket
286
287 set = new HashSet<>();
288 set.add(StandardSocketOptions.SO_RCVBUF);
289 set.add(StandardSocketOptions.SO_REUSEADDR);
290 if (reuseportsupported) {
291 set.add(StandardSocketOptions.SO_REUSEPORT);
292 }
293 set.add(StandardSocketOptions.IP_TOS);
294 set = Collections.unmodifiableSet(set);
295 options.put(ServerSocket.class, set);
296
297 // DatagramSocket
298
299 set = new HashSet<>();
300 set.add(StandardSocketOptions.SO_SNDBUF);
301 set.add(StandardSocketOptions.SO_RCVBUF);
302 set.add(StandardSocketOptions.SO_REUSEADDR);
303 if (reuseportsupported) {
304 set.add(StandardSocketOptions.SO_REUSEPORT);
305 }
306 set.add(StandardSocketOptions.IP_TOS);
307 if (flowsupported) {
308 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
309 }
310 set = Collections.unmodifiableSet(set);
311 options.put(DatagramSocket.class, set);
312
313 // MulticastSocket
314
315 set = new HashSet<>();
316 set.add(StandardSocketOptions.SO_SNDBUF);
317 set.add(StandardSocketOptions.SO_RCVBUF);
318 set.add(StandardSocketOptions.SO_REUSEADDR);
319 if (reuseportsupported) {
320 set.add(StandardSocketOptions.SO_REUSEPORT);
321 }
322 set.add(StandardSocketOptions.IP_TOS);
323 set.add(StandardSocketOptions.IP_MULTICAST_IF);
324 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
325 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
326 if (flowsupported) {
327 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
328 }
329 set = Collections.unmodifiableSet(set);
330 options.put(MulticastSocket.class, set);
331
332 return Collections.unmodifiableMap(options);
333 }
334 }
|
1 /*
2 * Copyright (c) 2016, 2017, 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
262 private static Map<Class<?>,Set<SocketOption<?>>> optionSets() {
263 Map<Class<?>,Set<SocketOption<?>>> options = new HashMap<>();
264 boolean flowsupported = PlatformSocketOptions.get().flowSupported();
265 boolean reuseportsupported = isReusePortAvailable();
266 // Socket
267
268 Set<SocketOption<?>> set = new HashSet<>();
269 set.add(StandardSocketOptions.SO_KEEPALIVE);
270 set.add(StandardSocketOptions.SO_SNDBUF);
271 set.add(StandardSocketOptions.SO_RCVBUF);
272 set.add(StandardSocketOptions.SO_REUSEADDR);
273 if (reuseportsupported) {
274 set.add(StandardSocketOptions.SO_REUSEPORT);
275 }
276 set.add(StandardSocketOptions.SO_LINGER);
277 set.add(StandardSocketOptions.IP_TOS);
278 set.add(StandardSocketOptions.TCP_NODELAY);
279 if (flowsupported) {
280 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
281 }
282 if (QuickAck.available) {
283 set.add(ExtendedSocketOptions.TCP_QUICKACK);
284 }
285 set = Collections.unmodifiableSet(set);
286 options.put(Socket.class, set);
287
288 // ServerSocket
289
290 set = new HashSet<>();
291 set.add(StandardSocketOptions.SO_RCVBUF);
292 set.add(StandardSocketOptions.SO_REUSEADDR);
293 if (reuseportsupported) {
294 set.add(StandardSocketOptions.SO_REUSEPORT);
295 }
296 if (QuickAck.available) {
297 set.add(ExtendedSocketOptions.TCP_QUICKACK);
298 }
299 set.add(StandardSocketOptions.IP_TOS);
300 set = Collections.unmodifiableSet(set);
301 options.put(ServerSocket.class, set);
302
303 // DatagramSocket
304
305 set = new HashSet<>();
306 set.add(StandardSocketOptions.SO_SNDBUF);
307 set.add(StandardSocketOptions.SO_RCVBUF);
308 set.add(StandardSocketOptions.SO_REUSEADDR);
309 if (reuseportsupported) {
310 set.add(StandardSocketOptions.SO_REUSEPORT);
311 }
312 set.add(StandardSocketOptions.IP_TOS);
313 if (flowsupported) {
314 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
315 }
316 set = Collections.unmodifiableSet(set);
317 options.put(DatagramSocket.class, set);
318
319 // MulticastSocket
320
321 set = new HashSet<>();
322 set.add(StandardSocketOptions.SO_SNDBUF);
323 set.add(StandardSocketOptions.SO_RCVBUF);
324 set.add(StandardSocketOptions.SO_REUSEADDR);
325 if (reuseportsupported) {
326 set.add(StandardSocketOptions.SO_REUSEPORT);
327 }
328 set.add(StandardSocketOptions.IP_TOS);
329 set.add(StandardSocketOptions.IP_MULTICAST_IF);
330 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
331 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
332 if (flowsupported) {
333 set.add(ExtendedSocketOptions.SO_FLOW_SLA);
334 }
335 set = Collections.unmodifiableSet(set);
336 options.put(MulticastSocket.class, set);
337
338 return Collections.unmodifiableMap(options);
339 }
340
341 /**
342 * Tells whether TCP_QUICKACK is supported.
343 */
344 static class QuickAck {
345
346 static final boolean available;
347
348 static {
349 Set<SocketOption<?>> s = new Socket().supportedOptions();
350 available = s.contains(ExtendedSocketOptions.TCP_QUICKACK);
351 }
352 }
353 }
|