1 /*
2 * Copyright (c) 1995, 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
345 * @param latency
346 * An {@code int} expressing the relative importance of low
347 * latency
348 *
349 * @param bandwidth
350 * An {@code int} expressing the relative importance of high
351 * bandwidth
352 *
353 * @since 1.5
354 */
355 protected void setPerformancePreferences(int connectionTime,
356 int latency,
357 int bandwidth)
358 {
359 /* Not implemented yet */
360 }
361
362 /**
363 * Called to set a socket option.
364 *
365 * @param name The socket option
366 *
367 * @param value The value of the socket option. A value of {@code null}
368 * may be valid for some options.
369 *
370 * @throws UnsupportedOperationException if the SocketImpl does not
371 * support the option
372 *
373 * @throws IOException if an I/O error occurs, or if the socket is closed.
374 *
375 * @since 1.9
376 */
377 protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
378 if (name == StandardSocketOptions.SO_KEEPALIVE) {
379 setOption(SocketOptions.SO_KEEPALIVE, value);
380 } else if (name == StandardSocketOptions.SO_SNDBUF) {
381 setOption(SocketOptions.SO_SNDBUF, value);
382 } else if (name == StandardSocketOptions.SO_RCVBUF) {
383 setOption(SocketOptions.SO_RCVBUF, value);
384 } else if (name == StandardSocketOptions.SO_REUSEADDR) {
385 setOption(SocketOptions.SO_REUSEADDR, value);
386 } else if (name == StandardSocketOptions.SO_LINGER) {
387 setOption(SocketOptions.SO_LINGER, value);
388 } else if (name == StandardSocketOptions.IP_TOS) {
389 setOption(SocketOptions.IP_TOS, value);
390 } else if (name == StandardSocketOptions.TCP_NODELAY) {
391 setOption(SocketOptions.TCP_NODELAY, value);
392 } else {
393 throw new UnsupportedOperationException("unsupported option");
394 }
395 }
396
397 /**
398 * Called to get a socket option.
399 *
400 * @param name The socket option
401 *
402 * @return the value of the named option
403 *
404 * @throws UnsupportedOperationException if the SocketImpl does not
405 * support the option.
406 *
407 * @throws IOException if an I/O error occurs, or if the socket is closed.
408 *
409 * @since 1.9
410 */
411 @SuppressWarnings("unchecked")
412 protected <T> T getOption(SocketOption<T> name) throws IOException {
413 if (name == StandardSocketOptions.SO_KEEPALIVE) {
414 return (T)getOption(SocketOptions.SO_KEEPALIVE);
415 } else if (name == StandardSocketOptions.SO_SNDBUF) {
416 return (T)getOption(SocketOptions.SO_SNDBUF);
417 } else if (name == StandardSocketOptions.SO_RCVBUF) {
418 return (T)getOption(SocketOptions.SO_RCVBUF);
419 } else if (name == StandardSocketOptions.SO_REUSEADDR) {
|
1 /*
2 * Copyright (c) 1995, 2015, 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
345 * @param latency
346 * An {@code int} expressing the relative importance of low
347 * latency
348 *
349 * @param bandwidth
350 * An {@code int} expressing the relative importance of high
351 * bandwidth
352 *
353 * @since 1.5
354 */
355 protected void setPerformancePreferences(int connectionTime,
356 int latency,
357 int bandwidth)
358 {
359 /* Not implemented yet */
360 }
361
362 /**
363 * Called to set a socket option.
364 *
365 * @param <T> The type of the socket option value
366 * @param name The socket option
367 *
368 * @param value The value of the socket option. A value of {@code null}
369 * may be valid for some options.
370 *
371 * @throws UnsupportedOperationException if the SocketImpl does not
372 * support the option
373 *
374 * @throws IOException if an I/O error occurs, or if the socket is closed.
375 *
376 * @since 1.9
377 */
378 protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
379 if (name == StandardSocketOptions.SO_KEEPALIVE) {
380 setOption(SocketOptions.SO_KEEPALIVE, value);
381 } else if (name == StandardSocketOptions.SO_SNDBUF) {
382 setOption(SocketOptions.SO_SNDBUF, value);
383 } else if (name == StandardSocketOptions.SO_RCVBUF) {
384 setOption(SocketOptions.SO_RCVBUF, value);
385 } else if (name == StandardSocketOptions.SO_REUSEADDR) {
386 setOption(SocketOptions.SO_REUSEADDR, value);
387 } else if (name == StandardSocketOptions.SO_LINGER) {
388 setOption(SocketOptions.SO_LINGER, value);
389 } else if (name == StandardSocketOptions.IP_TOS) {
390 setOption(SocketOptions.IP_TOS, value);
391 } else if (name == StandardSocketOptions.TCP_NODELAY) {
392 setOption(SocketOptions.TCP_NODELAY, value);
393 } else {
394 throw new UnsupportedOperationException("unsupported option");
395 }
396 }
397
398 /**
399 * Called to get a socket option.
400 *
401 * @param <T> The type of the socket option value
402 * @param name The socket option
403 *
404 * @return the value of the named option
405 *
406 * @throws UnsupportedOperationException if the SocketImpl does not
407 * support the option.
408 *
409 * @throws IOException if an I/O error occurs, or if the socket is closed.
410 *
411 * @since 1.9
412 */
413 @SuppressWarnings("unchecked")
414 protected <T> T getOption(SocketOption<T> name) throws IOException {
415 if (name == StandardSocketOptions.SO_KEEPALIVE) {
416 return (T)getOption(SocketOptions.SO_KEEPALIVE);
417 } else if (name == StandardSocketOptions.SO_SNDBUF) {
418 return (T)getOption(SocketOptions.SO_SNDBUF);
419 } else if (name == StandardSocketOptions.SO_RCVBUF) {
420 return (T)getOption(SocketOptions.SO_RCVBUF);
421 } else if (name == StandardSocketOptions.SO_REUSEADDR) {
|