< prev index next >

jdk/src/java.base/share/classes/java/net/DatagramSocketImpl.java

Print this page




 261      * file descriptor
 262      */
 263     protected FileDescriptor getFileDescriptor() {
 264         return fd;
 265     }
 266 
 267     /**
 268      * Called to set a socket option.
 269      *
 270      * @param <T> The type of the socket option value
 271      * @param name The socket option
 272      *
 273      * @param value The value of the socket option. A value of {@code null}
 274      *              may be valid for some options.
 275      *
 276      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
 277      *         support the option
 278      *
 279      * @throws NullPointerException if name is {@code null}
 280      * @throws IOException if an I/O problem occurs while attempting to set the option
 281      * @since 1.9
 282      */
 283     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
 284         if (name == StandardSocketOptions.SO_SNDBUF) {
 285             setOption(SocketOptions.SO_SNDBUF, value);
 286         } else if (name == StandardSocketOptions.SO_RCVBUF) {
 287             setOption(SocketOptions.SO_RCVBUF, value);
 288         } else if (name == StandardSocketOptions.SO_REUSEADDR) {
 289             setOption(SocketOptions.SO_REUSEADDR, value);
 290         } else if (name == StandardSocketOptions.IP_TOS) {
 291             setOption(SocketOptions.IP_TOS, value);
 292         } else if (name == StandardSocketOptions.IP_MULTICAST_IF &&
 293             (getDatagramSocket() instanceof MulticastSocket)) {
 294             setOption(SocketOptions.IP_MULTICAST_IF2, value);
 295         } else if (name == StandardSocketOptions.IP_MULTICAST_TTL &&
 296             (getDatagramSocket() instanceof MulticastSocket)) {
 297             if (! (value instanceof Integer)) {
 298                 throw new IllegalArgumentException("not an integer");
 299             }
 300             setTimeToLive((Integer)value);
 301         } else if (name == StandardSocketOptions.IP_MULTICAST_LOOP &&
 302             (getDatagramSocket() instanceof MulticastSocket)) {
 303             setOption(SocketOptions.IP_MULTICAST_LOOP, value);
 304         } else {
 305             throw new UnsupportedOperationException("unsupported option");
 306         }
 307     }
 308 
 309     /**
 310      * Called to get a socket option.
 311      *
 312      * @return the socket option
 313      * @param <T> The type of the socket option value
 314      * @param name The socket option
 315      *
 316      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
 317      *         support the option
 318      *
 319      * @throws NullPointerException if name is {@code null}
 320      * @throws IOException if an I/O problem occurs while attempting to set the option
 321      *
 322      * @since 1.9
 323      */
 324     @SuppressWarnings("unchecked")
 325     protected <T> T getOption(SocketOption<T> name) throws IOException {
 326         if (name == StandardSocketOptions.SO_SNDBUF) {
 327             return (T) getOption(SocketOptions.SO_SNDBUF);
 328         } else if (name == StandardSocketOptions.SO_RCVBUF) {
 329             return (T) getOption(SocketOptions.SO_RCVBUF);
 330         } else if (name == StandardSocketOptions.SO_REUSEADDR) {
 331             return (T) getOption(SocketOptions.SO_REUSEADDR);
 332         } else if (name == StandardSocketOptions.IP_TOS) {
 333             return (T) getOption(SocketOptions.IP_TOS);
 334         } else if (name == StandardSocketOptions.IP_MULTICAST_IF &&
 335             (getDatagramSocket() instanceof MulticastSocket)) {
 336             return (T) getOption(SocketOptions.IP_MULTICAST_IF2);
 337         } else if (name == StandardSocketOptions.IP_MULTICAST_TTL &&
 338             (getDatagramSocket() instanceof MulticastSocket)) {
 339             Integer ttl = getTimeToLive();
 340             return (T)ttl;
 341         } else if (name == StandardSocketOptions.IP_MULTICAST_LOOP &&
 342             (getDatagramSocket() instanceof MulticastSocket)) {




 261      * file descriptor
 262      */
 263     protected FileDescriptor getFileDescriptor() {
 264         return fd;
 265     }
 266 
 267     /**
 268      * Called to set a socket option.
 269      *
 270      * @param <T> The type of the socket option value
 271      * @param name The socket option
 272      *
 273      * @param value The value of the socket option. A value of {@code null}
 274      *              may be valid for some options.
 275      *
 276      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
 277      *         support the option
 278      *
 279      * @throws NullPointerException if name is {@code null}
 280      * @throws IOException if an I/O problem occurs while attempting to set the option
 281      * @since 9
 282      */
 283     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
 284         if (name == StandardSocketOptions.SO_SNDBUF) {
 285             setOption(SocketOptions.SO_SNDBUF, value);
 286         } else if (name == StandardSocketOptions.SO_RCVBUF) {
 287             setOption(SocketOptions.SO_RCVBUF, value);
 288         } else if (name == StandardSocketOptions.SO_REUSEADDR) {
 289             setOption(SocketOptions.SO_REUSEADDR, value);
 290         } else if (name == StandardSocketOptions.IP_TOS) {
 291             setOption(SocketOptions.IP_TOS, value);
 292         } else if (name == StandardSocketOptions.IP_MULTICAST_IF &&
 293             (getDatagramSocket() instanceof MulticastSocket)) {
 294             setOption(SocketOptions.IP_MULTICAST_IF2, value);
 295         } else if (name == StandardSocketOptions.IP_MULTICAST_TTL &&
 296             (getDatagramSocket() instanceof MulticastSocket)) {
 297             if (! (value instanceof Integer)) {
 298                 throw new IllegalArgumentException("not an integer");
 299             }
 300             setTimeToLive((Integer)value);
 301         } else if (name == StandardSocketOptions.IP_MULTICAST_LOOP &&
 302             (getDatagramSocket() instanceof MulticastSocket)) {
 303             setOption(SocketOptions.IP_MULTICAST_LOOP, value);
 304         } else {
 305             throw new UnsupportedOperationException("unsupported option");
 306         }
 307     }
 308 
 309     /**
 310      * Called to get a socket option.
 311      *
 312      * @return the socket option
 313      * @param <T> The type of the socket option value
 314      * @param name The socket option
 315      *
 316      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
 317      *         support the option
 318      *
 319      * @throws NullPointerException if name is {@code null}
 320      * @throws IOException if an I/O problem occurs while attempting to set the option
 321      *
 322      * @since 9
 323      */
 324     @SuppressWarnings("unchecked")
 325     protected <T> T getOption(SocketOption<T> name) throws IOException {
 326         if (name == StandardSocketOptions.SO_SNDBUF) {
 327             return (T) getOption(SocketOptions.SO_SNDBUF);
 328         } else if (name == StandardSocketOptions.SO_RCVBUF) {
 329             return (T) getOption(SocketOptions.SO_RCVBUF);
 330         } else if (name == StandardSocketOptions.SO_REUSEADDR) {
 331             return (T) getOption(SocketOptions.SO_REUSEADDR);
 332         } else if (name == StandardSocketOptions.IP_TOS) {
 333             return (T) getOption(SocketOptions.IP_TOS);
 334         } else if (name == StandardSocketOptions.IP_MULTICAST_IF &&
 335             (getDatagramSocket() instanceof MulticastSocket)) {
 336             return (T) getOption(SocketOptions.IP_MULTICAST_IF2);
 337         } else if (name == StandardSocketOptions.IP_MULTICAST_TTL &&
 338             (getDatagramSocket() instanceof MulticastSocket)) {
 339             Integer ttl = getTimeToLive();
 340             return (T)ttl;
 341         } else if (name == StandardSocketOptions.IP_MULTICAST_LOOP &&
 342             (getDatagramSocket() instanceof MulticastSocket)) {


< prev index next >