Java Code Examples for java.net.SocketOption

The following are top voted examples for showing how to use java.net.SocketOption. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 2
Project: OpenJSharp   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 3
Project: OpenJSharp   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 4
Project: OpenJSharp   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 5
Project: jdk8u-jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 6
Project: jdk8u-jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 7
Project: jdk8u-jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 8
Project: jdk8u-jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 9
Project: openjdk-jdk10   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 10
Project: openjdk-jdk10   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 11
Project: openjdk-jdk10   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 12
Project: openjdk-jdk10   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 13
Project: openjdk-jdk10   File: ExtendedSocketOptions.java   Source Code and License 6 votes vote down vote up
@Override
public void setOption(FileDescriptor fd,
                      SocketOption<?> option,
                      Object value)
    throws SocketException
{
    SecurityManager sm = System.getSecurityManager();
    if (sm != null)
        sm.checkPermission(new NetworkPermission("setOption." + option.name()));

    if (fd == null || !fd.valid())
        throw new SocketException("socket closed");

    if (option == SO_FLOW_SLA) {
        assert flowSupported;
        SocketFlow flow = checkValueType(value, option.type());
        setFlowOption(fd, flow);
    } else {
        throw new InternalError("Unexpected option " + option);
    }
}
 
Example 14
Project: openjdk-jdk10   File: ExtendedSocketOptions.java   Source Code and License 6 votes vote down vote up
@Override
public Object getOption(FileDescriptor fd,
                        SocketOption<?> option)
    throws SocketException
{
    SecurityManager sm = System.getSecurityManager();
    if (sm != null)
        sm.checkPermission(new NetworkPermission("getOption." + option.name()));

    if (fd == null || !fd.valid())
        throw new SocketException("socket closed");

    if (option == SO_FLOW_SLA) {
        assert flowSupported;
        SocketFlow flow = SocketFlow.create();
        getFlowOption(fd, flow);
        return flow;
    } else {
        throw new InternalError("Unexpected option " + option);
    }
}
 
Example 15
Project: openjdk9   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 16
Project: openjdk9   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 17
Project: openjdk9   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 18
Project: openjdk9   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 19
Project: openjdk9   File: ExtendedSocketOptions.java   Source Code and License 6 votes vote down vote up
@Override
public void setOption(FileDescriptor fd,
                      SocketOption<?> option,
                      Object value)
    throws SocketException
{
    SecurityManager sm = System.getSecurityManager();
    if (sm != null)
        sm.checkPermission(new NetworkPermission("setOption." + option.name()));

    if (fd == null || !fd.valid())
        throw new SocketException("socket closed");

    if (option == SO_FLOW_SLA) {
        assert flowSupported;
        SocketFlow flow = checkValueType(value, option.type());
        setFlowOption(fd, flow);
    } else {
        throw new InternalError("Unexpected option " + option);
    }
}
 
Example 20
Project: openjdk9   File: ExtendedSocketOptions.java   Source Code and License 6 votes vote down vote up
@Override
public Object getOption(FileDescriptor fd,
                        SocketOption<?> option)
    throws SocketException
{
    SecurityManager sm = System.getSecurityManager();
    if (sm != null)
        sm.checkPermission(new NetworkPermission("getOption." + option.name()));

    if (fd == null || !fd.valid())
        throw new SocketException("socket closed");

    if (option == SO_FLOW_SLA) {
        assert flowSupported;
        SocketFlow flow = SocketFlow.create();
        getFlowOption(fd, flow);
        return flow;
    } else {
        throw new InternalError("Unexpected option " + option);
    }
}
 
Example 21
Project: jdk8u_jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 22
Project: jdk8u_jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 23
Project: jdk8u_jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 24
Project: jdk8u_jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 25
Project: lookaside_java-1.8.0-openjdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 26
Project: lookaside_java-1.8.0-openjdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 27
Project: lookaside_java-1.8.0-openjdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 28
Project: lookaside_java-1.8.0-openjdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 29
Project: j2objc   File: NioUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the supplied option on the channel to have the value if option is a member of
 * allowedOptions.
 *
 * @throws IOException
 *          if the value could not be set due to IO errors.
 * @throws IllegalArgumentException
 *          if the socket option or the value is invalid.
 * @throws UnsupportedOperationException
 *          if the option is not a member of allowedOptions.
 * @throws ClosedChannelException
 *          if the channel is closed
 */
public static <T> void setSocketOption(
        FileDescriptorChannel channel, Set<SocketOption<?>> allowedOptions,
        SocketOption<T> option, T value)
        throws IOException {

    if (!(option instanceof StandardSocketOptions.SocketOptionImpl)) {
        throw new IllegalArgumentException("SocketOption must come from StandardSocketOptions");
    }
    if (!allowedOptions.contains(option)) {
        throw new UnsupportedOperationException(
                option + " is not supported for this type of socket");
    }
    if (!channel.getFD().valid()) {
        throw new ClosedChannelException();
    }
    ((StandardSocketOptions.SocketOptionImpl<T>) option).setValue(channel.getFD(), value);
}
 
Example 30
Project: j2objc   File: NioUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Gets the supplied option from the channel if option is a member of allowedOptions.
 *
 * @throws IOException
 *          if the value could not be read due to IO errors.
 * @throws IllegalArgumentException
 *          if the socket option is invalid.
 * @throws UnsupportedOperationException
 *          if the option is not a member of allowedOptions.
 * @throws ClosedChannelException
 *          if the channel is closed
 */
public static <T> T getSocketOption(
        FileDescriptorChannel channel, Set<SocketOption<?>> allowedOptions,
        SocketOption<T> option)
        throws IOException {

    if (!(option instanceof StandardSocketOptions.SocketOptionImpl)) {
        throw new IllegalArgumentException("SocketOption must come from StandardSocketOptions");
    }
    if (!allowedOptions.contains(option)) {
        throw new UnsupportedOperationException(
                option + " is not supported for this type of socket");
    }
    if (!channel.getFD().valid()) {
        throw new ClosedChannelException();
    }
    return ((StandardSocketOptions.SocketOptionImpl<T>) option).getValue(channel.getFD());
}
 
Example 31
Project: jephyr   File: NioSocketImpl.java   Source Code and License 6 votes vote down vote up
private static SocketOption<?> findOption(int optID) throws SocketException {
    switch (optID) {
        case TCP_NODELAY:
            return StandardSocketOptions.TCP_NODELAY;
        case SO_REUSEADDR:
            return StandardSocketOptions.SO_REUSEADDR;
        case SO_BROADCAST:
            return StandardSocketOptions.SO_BROADCAST;
        case IP_MULTICAST_IF:
            return StandardSocketOptions.IP_MULTICAST_IF;
        case IP_MULTICAST_LOOP:
            return StandardSocketOptions.IP_MULTICAST_LOOP;
        case IP_TOS:
            return StandardSocketOptions.IP_TOS;
        case SO_LINGER:
            return StandardSocketOptions.SO_LINGER;
        case SO_SNDBUF:
            return StandardSocketOptions.SO_SNDBUF;
        case SO_RCVBUF:
            return StandardSocketOptions.SO_RCVBUF;
        case SO_KEEPALIVE:
            return StandardSocketOptions.SO_KEEPALIVE;
        default:
            throw new SocketException("unrecognized TCP option: " + optID);
    }
}
 
Example 32
Project: infobip-open-jdk-8   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 33
Project: infobip-open-jdk-8   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 34
Project: infobip-open-jdk-8   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 35
Project: infobip-open-jdk-8   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 36
Project: jdk8u-dev-jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name,
                                                           T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 37
Project: jdk8u-dev-jdk   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 38
Project: jdk8u-dev-jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value)
    throws IOException
{
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (writeShutdown)
            throw new IOException("Connection has been shutdown for writing");
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            isReuseAddress = (Boolean)value;
        } else {
            Net.setSocketOption(fd, Net.UNSPEC, name, value);
        }
        return this;
    } finally {
        end();
    }
}
 
Example 39
Project: jdk8u-dev-jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public final <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    try {
        begin();
        if (name == StandardSocketOptions.SO_REUSEADDR &&
                Net.useExclusiveBind())
        {
            // SO_REUSEADDR emulated when using exclusive bind
            return (T)Boolean.valueOf(isReuseAddress);
        }
        return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    } finally {
        end();
    }
}
 
Example 40
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException {
  try {
    SSLSocket.class.getMethod("setOption", SocketOption.class, Object.class).invoke(delegate, name, value);
    return this;
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 41
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> T getOption(SocketOption<T> name) throws IOException {
  try {
    return (T) SSLSocket.class.getMethod("getOption", SocketOption.class).invoke(delegate, name);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 42
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public Set<SocketOption<?>> supportedOptions() {
  try {
    return (Set<SocketOption<?>>) SSLSocket.class.getMethod("supportedOptions").invoke(delegate);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 43
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException {
  try {
    SSLSocket.class.getMethod("setOption", SocketOption.class, Object.class).invoke(delegate, name, value);
    return this;
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 44
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> T getOption(SocketOption<T> name) throws IOException {
  try {
    return (T) SSLSocket.class.getMethod("getOption", SocketOption.class).invoke(delegate, name);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 45
Project: GitHub   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public Set<SocketOption<?>> supportedOptions() {
  try {
    return (Set<SocketOption<?>>) SSLSocket.class.getMethod("supportedOptions").invoke(delegate);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 46
Project: OpenJSharp   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    set.add(StandardSocketOptions.TCP_NODELAY);
    if (ExtendedOptionsImpl.flowSupported()) {
        set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
    }
    return Collections.unmodifiableSet(set);
}
 
Example 47
Project: jdk8u-jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    set.add(StandardSocketOptions.TCP_NODELAY);
    if (ExtendedOptionsImpl.flowSupported()) {
        set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
    }
    return Collections.unmodifiableSet(set);
}
 
Example 48
Project: openjdk-jdk10   File: ExtendedSocketOptions.java   Source Code and License 5 votes vote down vote up
@Override
public void setOption(FileDescriptor fd, SocketOption<?> option, Object value)
    throws SocketException
{
    throw new UnsupportedOperationException(
            "no extended options: " + option.name());
}
 
Example 49
Project: openjdk-jdk10   File: ExtendedSocketOptions.java   Source Code and License 5 votes vote down vote up
@Override
public Object getOption(FileDescriptor fd, SocketOption<?> option)
    throws SocketException
{
    throw new UnsupportedOperationException(
            "no extended options: " + option.name());
}
 
Example 50
Project: openjdk-jdk10   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<>(2);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    if (Net.isReusePortAvailable()) {
        set.add(StandardSocketOptions.SO_REUSEPORT);
    }
    return Collections.unmodifiableSet(set);
}
 
Example 51
Project: openjdk-jdk10   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    if (Net.isReusePortAvailable()) {
        set.add(StandardSocketOptions.SO_REUSEPORT);
    }
    set.add(StandardSocketOptions.TCP_NODELAY);
    ExtendedSocketOptions extendedOptions =
            ExtendedSocketOptions.getInstance();
    set.addAll(extendedOptions.options());
    return Collections.unmodifiableSet(set);
}
 
Example 52
Project: openjdk9   File: ExtendedSocketOptions.java   Source Code and License 5 votes vote down vote up
@Override
public void setOption(FileDescriptor fd, SocketOption<?> option, Object value)
    throws SocketException
{
    throw new UnsupportedOperationException(
            "no extended options: " + option.name());
}
 
Example 53
Project: openjdk9   File: ExtendedSocketOptions.java   Source Code and License 5 votes vote down vote up
@Override
public Object getOption(FileDescriptor fd, SocketOption<?> option)
    throws SocketException
{
    throw new UnsupportedOperationException(
            "no extended options: " + option.name());
}
 
Example 54
Project: openjdk9   File: AsynchronousServerSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<>(2);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    if (Net.isReusePortAvailable()) {
        set.add(StandardSocketOptions.SO_REUSEPORT);
    }
    return Collections.unmodifiableSet(set);
}
 
Example 55
Project: openjdk9   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    if (Net.isReusePortAvailable()) {
        set.add(StandardSocketOptions.SO_REUSEPORT);
    }
    set.add(StandardSocketOptions.TCP_NODELAY);
    ExtendedSocketOptions extendedOptions =
            ExtendedSocketOptions.getInstance();
    set.addAll(extendedOptions.options());
    return Collections.unmodifiableSet(set);
}
 
Example 56
Project: Okhttp   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException {
  try {
    SSLSocket.class.getMethod("setOption", SocketOption.class, Object.class).invoke(delegate, name, value);
    return this;
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 57
Project: Okhttp   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public <T> T getOption(SocketOption<T> name) throws IOException {
  try {
    return (T) SSLSocket.class.getMethod("getOption", SocketOption.class).invoke(delegate, name);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 58
Project: Okhttp   File: DelegatingSSLSocket.java   Source Code and License 5 votes vote down vote up
public Set<SocketOption<?>> supportedOptions() {
  try {
    return (Set<SocketOption<?>>) SSLSocket.class.getMethod("supportedOptions").invoke(delegate);
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new AssertionError();
  }
}
 
Example 59
Project: jdk8u_jdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    set.add(StandardSocketOptions.TCP_NODELAY);
    if (ExtendedOptionsImpl.flowSupported()) {
        set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
    }
    return Collections.unmodifiableSet(set);
}
 
Example 60
Project: lookaside_java-1.8.0-openjdk   File: AsynchronousSocketChannelImpl.java   Source Code and License 5 votes vote down vote up
private static Set<SocketOption<?>> defaultOptions() {
    HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5);
    set.add(StandardSocketOptions.SO_SNDBUF);
    set.add(StandardSocketOptions.SO_RCVBUF);
    set.add(StandardSocketOptions.SO_KEEPALIVE);
    set.add(StandardSocketOptions.SO_REUSEADDR);
    set.add(StandardSocketOptions.TCP_NODELAY);
    if (ExtendedOptionsImpl.flowSupported()) {
        set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
    }
    return Collections.unmodifiableSet(set);
}