static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
                                SocketOption<?> name, Object value)
        throws IOException
    {
        if (value == null)
            throw new IllegalArgumentException("Invalid option value");

        // only simple values supported by this method
        Class<?> type = name.type();
        if (type != Integer.class && type != Boolean.class)
            throw new AssertionError("Should not reach here");

        // special handling
        if (name == StandardSocketOptions.SO_RCVBUF ||
            name == StandardSocketOptions.SO_SNDBUF)
        {
            int i = ((Integer)value).intValue();
            if (i < 0)
                throw new IllegalArgumentException("Invalid send/receive buffer size");
        }
        if (name == StandardSocketOptions.SO_LINGER) {
            int i = ((Integer)value).intValue();
            if (i < 0)
                value = Integer.valueOf(-1);
            if (i > 65535)
                value = Integer.valueOf(65535);
        }
        if (name == StandardSocketOptions.IP_TOS) {
            int i = ((Integer)value).intValue();
            if (i < 0 || i > 255)
                throw new IllegalArgumentException("Invalid IP_TOS value");
        }
        if (name == StandardSocketOptions.IP_MULTICAST_TTL) {
            int i = ((Integer)value).intValue();
            if (i < 0 || i > 255)
                throw new IllegalArgumentException("Invalid TTL/hop value");
        }

        // map option name to platform level/name
        OptionKey key = SocketOptionRegistry.findOption(name, family);
        if (key == null)
            throw new AssertionError("Option not found");

        int arg;
        if (type == Integer.class) {
            arg = ((Integer)value).intValue();
        } else {
            boolean b = ((Boolean)value).booleanValue();
            arg = (b) ? 1 : 0;
        }

        boolean mayNeedConversion = (family == UNSPEC);
        setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg);
    }
static void setSocketOption ( FileDescriptor fd , ProtocolFamily family , SocketOption < ? > name , Object value ) throws IOException { if ( value == null ) throw new IllegalArgumentException ( "Invalid option value" ) ; Class < ? > type = name . type ( ) ; if ( type != Integer . class && type != Boolean . class ) throw new AssertionError ( "Should not reach here" ) ; if ( name == StandardSocketOptions . SO_RCVBUF || name == StandardSocketOptions . SO_SNDBUF ) { int i = ( ( Integer ) value ) . intValue ( ) ; if ( i < 0 ) throw new IllegalArgumentException ( "Invalid send/receive buffer size" ) ; } if ( name == StandardSocketOptions . SO_LINGER ) { int i = ( ( Integer ) value ) . intValue ( ) ; if ( i < 0 ) value = Integer . valueOf ( - 1 ) ; if ( i > 65535 ) value = Integer . valueOf ( 65535 ) ; } if ( name == StandardSocketOptions . IP_TOS ) { int i = ( ( Integer ) value ) . intValue ( ) ; if ( i < 0 || i > 255 ) throw new IllegalArgumentException ( "Invalid IP_TOS value" ) ; } if ( name == StandardSocketOptions . IP_MULTICAST_TTL ) { int i = ( ( Integer ) value ) . intValue ( ) ; if ( i < 0 || i > 255 ) throw new IllegalArgumentException ( "Invalid TTL/hop value" ) ; } OptionKey key = SocketOptionRegistry . findOption ( name , family ) ; if ( key == null ) throw new AssertionError ( "Option not found" ) ; int arg ; if ( type == Integer . class ) { arg = ( ( Integer ) value ) . intValue ( ) ; } else { boolean b = ( ( Boolean ) value ) . booleanValue ( ) ; arg = ( b ) ? 1 : 0 ; } boolean mayNeedConversion = ( family == UNSPEC ) ; setIntOption0 ( fd , mayNeedConversion , key . level ( ) , key . name ( ) , arg ) ; }
-- Socket options