本文整理匯總了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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}