8190843: can not set/get extendedOptions to ServerSocket

Reviewed-by: chegar, rriggs
This commit is contained in:
Vyom Tewari 2017-12-04 13:24:00 +05:30
parent 06331455d2
commit d55fdd6c56
4 changed files with 119 additions and 59 deletions

View file

@ -45,41 +45,33 @@ class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
ExtendedSocketOptions.getInstance();
protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
super.setOption(name, value);
if (isClosed()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value);
} else {
if (supportedOptions().contains(name)) {
super.setOption(name, value);
} else {
throw new UnsupportedOperationException("unsupported option");
}
super.setOption(name, value);
}
} else {
if (isClosed()) {
throw new SocketException("Socket closed");
}
extendedOptions.setOption(fd, name, value);
throw new UnsupportedOperationException("unsupported option");
}
}
@SuppressWarnings("unchecked")
protected <T> T getOption(SocketOption<T> name) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
return super.getOption(name);
if (isClosed()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
return (T) extendedOptions.getOption(fd, name);
} else {
if (supportedOptions().contains(name)) {
return super.getOption(name);
} else {
throw new UnsupportedOperationException("unsupported option");
}
return super.getOption(name);
}
} else {
if (isClosed()) {
throw new SocketException("Socket closed");
}
return (T) extendedOptions.getOption(fd, name);
throw new UnsupportedOperationException("unsupported option");
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,58 +58,57 @@ class PlainSocketImpl extends AbstractPlainSocketImpl
ExtendedSocketOptions.getInstance();
protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
super.setOption(name, value);
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value);
} else {
if (supportedOptions().contains(name)) {
super.setOption(name, value);
} else {
throw new UnsupportedOperationException("unsupported option");
}
super.setOption(name, value);
}
} else {
if (getSocket() == null) {
throw new UnsupportedOperationException("unsupported option");
}
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
extendedOptions.setOption(fd, name, value);
throw new UnsupportedOperationException("unsupported option");
}
}
@SuppressWarnings("unchecked")
protected <T> T getOption(SocketOption<T> name) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
return super.getOption(name);
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
return (T) extendedOptions.getOption(fd, name);
} else {
if (supportedOptions().contains(name)) {
return super.getOption(name);
} else {
throw new UnsupportedOperationException("unsupported option");
}
return super.getOption(name);
}
} else {
if (getSocket() == null) {
throw new UnsupportedOperationException("unsupported option");
}
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
return (T) extendedOptions.getOption(fd, name);
throw new UnsupportedOperationException("unsupported option");
}
}
protected Set<SocketOption<?>> supportedOptions() {
HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions());
if (getSocket() != null) {
options.addAll(extendedOptions.options());
}
addExtSocketOptions(extendedOptions.options(), options);
return options;
}
private void addExtSocketOptions(Set<SocketOption<?>> extOptions,
Set<SocketOption<?>> options) {
extOptions.forEach((option) -> {
if (option.name().equals("SO_FLOW_SLA")) {
// SO_FLOW_SLA is Solaris specific option which is not applicable
// for ServerSockets.
// getSocket() will always return null for server socket
if (getSocket() != null) {
options.add(option);
}
} else {
options.add(option);
}
});
}
protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
if (opt == SocketOptions.SO_REUSEPORT &&
!supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {