/**
* 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);
}
NioUtils.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:j2objc
作者:
评论列表
文章目录