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 (getSocket() != null)) { 381 setOption(SocketOptions.SO_KEEPALIVE, value); 382 } else if (name == StandardSocketOptions.SO_SNDBUF && 383 (getSocket() != null)) { 384 setOption(SocketOptions.SO_SNDBUF, value); 385 } else if (name == StandardSocketOptions.SO_RCVBUF) { 386 setOption(SocketOptions.SO_RCVBUF, value); 387 } else if (name == StandardSocketOptions.SO_REUSEADDR) { 388 setOption(SocketOptions.SO_REUSEADDR, value); 389 } else if (name == StandardSocketOptions.SO_LINGER && 390 (getSocket() != null)) { 391 setOption(SocketOptions.SO_LINGER, value); 392 } else if (name == StandardSocketOptions.IP_TOS) { 393 setOption(SocketOptions.IP_TOS, value); 394 } else if (name == StandardSocketOptions.TCP_NODELAY && 395 (getSocket() != null)) { 396 setOption(SocketOptions.TCP_NODELAY, value); 397 } else { 398 throw new UnsupportedOperationException("unsupported option"); 399 } 400 } 401 402 /** 403 * Called to get a socket option. 404 * 405 * @param <T> The type of the socket option value 406 * @param name The socket option 407 * 408 * @return the value of the named option 409 * 410 * @throws UnsupportedOperationException if the SocketImpl does not 411 * support the option. 412 * 413 * @throws IOException if an I/O error occurs, or if the socket is closed. 414 * 415 * @since 1.9 416 */ 417 @SuppressWarnings("unchecked") 418 protected <T> T getOption(SocketOption<T> name) throws IOException { 419 if (name == StandardSocketOptions.SO_KEEPALIVE && 420 (getSocket() != null)) { 421 return (T)getOption(SocketOptions.SO_KEEPALIVE); 422 } else if (name == StandardSocketOptions.SO_SNDBUF && 423 (getSocket() != null)) { 424 return (T)getOption(SocketOptions.SO_SNDBUF); 425 } else if (name == StandardSocketOptions.SO_RCVBUF) { 426 return (T)getOption(SocketOptions.SO_RCVBUF); 427 } else if (name == StandardSocketOptions.SO_REUSEADDR) { 428 return (T)getOption(SocketOptions.SO_REUSEADDR); 429 } else if (name == StandardSocketOptions.SO_LINGER && 430 (getSocket() != null)) { 431 return (T)getOption(SocketOptions.SO_LINGER); 432 } else if (name == StandardSocketOptions.IP_TOS) { 433 return (T)getOption(SocketOptions.IP_TOS); 434 } else if (name == StandardSocketOptions.TCP_NODELAY && 435 (getSocket() != null)) { | 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 9 377 */ 378 protected <T> void setOption(SocketOption<T> name, T value) throws IOException { 379 if (name == StandardSocketOptions.SO_KEEPALIVE && 380 (getSocket() != null)) { 381 setOption(SocketOptions.SO_KEEPALIVE, value); 382 } else if (name == StandardSocketOptions.SO_SNDBUF && 383 (getSocket() != null)) { 384 setOption(SocketOptions.SO_SNDBUF, value); 385 } else if (name == StandardSocketOptions.SO_RCVBUF) { 386 setOption(SocketOptions.SO_RCVBUF, value); 387 } else if (name == StandardSocketOptions.SO_REUSEADDR) { 388 setOption(SocketOptions.SO_REUSEADDR, value); 389 } else if (name == StandardSocketOptions.SO_LINGER && 390 (getSocket() != null)) { 391 setOption(SocketOptions.SO_LINGER, value); 392 } else if (name == StandardSocketOptions.IP_TOS) { 393 setOption(SocketOptions.IP_TOS, value); 394 } else if (name == StandardSocketOptions.TCP_NODELAY && 395 (getSocket() != null)) { 396 setOption(SocketOptions.TCP_NODELAY, value); 397 } else { 398 throw new UnsupportedOperationException("unsupported option"); 399 } 400 } 401 402 /** 403 * Called to get a socket option. 404 * 405 * @param <T> The type of the socket option value 406 * @param name The socket option 407 * 408 * @return the value of the named option 409 * 410 * @throws UnsupportedOperationException if the SocketImpl does not 411 * support the option. 412 * 413 * @throws IOException if an I/O error occurs, or if the socket is closed. 414 * 415 * @since 9 416 */ 417 @SuppressWarnings("unchecked") 418 protected <T> T getOption(SocketOption<T> name) throws IOException { 419 if (name == StandardSocketOptions.SO_KEEPALIVE && 420 (getSocket() != null)) { 421 return (T)getOption(SocketOptions.SO_KEEPALIVE); 422 } else if (name == StandardSocketOptions.SO_SNDBUF && 423 (getSocket() != null)) { 424 return (T)getOption(SocketOptions.SO_SNDBUF); 425 } else if (name == StandardSocketOptions.SO_RCVBUF) { 426 return (T)getOption(SocketOptions.SO_RCVBUF); 427 } else if (name == StandardSocketOptions.SO_REUSEADDR) { 428 return (T)getOption(SocketOptions.SO_REUSEADDR); 429 } else if (name == StandardSocketOptions.SO_LINGER && 430 (getSocket() != null)) { 431 return (T)getOption(SocketOptions.SO_LINGER); 432 } else if (name == StandardSocketOptions.IP_TOS) { 433 return (T)getOption(SocketOptions.IP_TOS); 434 } else if (name == StandardSocketOptions.TCP_NODELAY && 435 (getSocket() != null)) { |