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) { 422 return (T)getOption(SocketOptions.SO_REUSEADDR); 423 } else if (name == StandardSocketOptions.SO_LINGER) { 424 return (T)getOption(SocketOptions.SO_LINGER); 425 } else if (name == StandardSocketOptions.IP_TOS) { 426 return (T)getOption(SocketOptions.IP_TOS); 427 } else if (name == StandardSocketOptions.TCP_NODELAY) { 428 return (T)getOption(SocketOptions.TCP_NODELAY); 429 } else { 430 throw new UnsupportedOperationException("unsupported option"); 431 } | 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 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 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) { 422 return (T)getOption(SocketOptions.SO_REUSEADDR); 423 } else if (name == StandardSocketOptions.SO_LINGER) { 424 return (T)getOption(SocketOptions.SO_LINGER); 425 } else if (name == StandardSocketOptions.IP_TOS) { 426 return (T)getOption(SocketOptions.IP_TOS); 427 } else if (name == StandardSocketOptions.TCP_NODELAY) { 428 return (T)getOption(SocketOptions.TCP_NODELAY); 429 } else { 430 throw new UnsupportedOperationException("unsupported option"); 431 } |