當前位置: 首頁>>代碼示例>>Java>>正文


Java StandardSocketOptions.SO_REUSEADDR屬性代碼示例

本文整理匯總了Java中java.net.StandardSocketOptions.SO_REUSEADDR屬性的典型用法代碼示例。如果您正苦於以下問題:Java StandardSocketOptions.SO_REUSEADDR屬性的具體用法?Java StandardSocketOptions.SO_REUSEADDR怎麽用?Java StandardSocketOptions.SO_REUSEADDR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.net.StandardSocketOptions的用法示例。


在下文中一共展示了StandardSocketOptions.SO_REUSEADDR屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setOption

@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();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:AsynchronousServerSocketChannelImpl.java

示例2: getOption

@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();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:AsynchronousServerSocketChannelImpl.java

示例3: setOption

@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();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:AsynchronousSocketChannelImpl.java

示例4: findOption

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);
    }
}
 
開發者ID:yngui,項目名稱:jephyr,代碼行數:26,代碼來源:NioSocketImpl.java


注:本文中的java.net.StandardSocketOptions.SO_REUSEADDR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。