8244582: Remove terminally deprecated Solaris-specific SO_FLOW_SLA socket option
This patch removes ExtendedSocketOptions.SO_FLOW_SLA, SocketFlow and SocketFlow.Status which were terminally deprecated in JDK 14 in preparation for the removal of the Solaris port. Reviewed-by: alanb, dfuchs, chegar, vtewari
This commit is contained in:
parent
4d75aef609
commit
d071ed0294
@ -59,19 +59,6 @@ public final class ExtendedSocketOptions {
|
||||
|
||||
private ExtendedSocketOptions() { }
|
||||
|
||||
/**
|
||||
* Service level properties. When a security manager is installed,
|
||||
* setting or getting this option requires a {@link NetworkPermission}
|
||||
* {@code ("setOption.SO_FLOW_SLA")} or {@code "getOption.SO_FLOW_SLA"}
|
||||
* respectively.
|
||||
* @deprecated This is supported only on Solaris. Due to deprecation
|
||||
* of Solaris port, this option is also deprecated.
|
||||
*/
|
||||
@Deprecated(since="14", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public static final SocketOption<SocketFlow> SO_FLOW_SLA = new
|
||||
ExtSocketOption<SocketFlow>("SO_FLOW_SLA", SocketFlow.class);
|
||||
|
||||
/**
|
||||
* Disable Delayed Acknowledgements.
|
||||
*
|
||||
@ -196,8 +183,6 @@ public final class ExtendedSocketOptions {
|
||||
private static final PlatformSocketOptions platformSocketOptions =
|
||||
PlatformSocketOptions.get();
|
||||
|
||||
private static final boolean flowSupported =
|
||||
platformSocketOptions.flowSupported();
|
||||
private static final boolean quickAckSupported =
|
||||
platformSocketOptions.quickAckSupported();
|
||||
private static final boolean keepAliveOptSupported =
|
||||
@ -208,9 +193,6 @@ public final class ExtendedSocketOptions {
|
||||
|
||||
static Set<SocketOption<?>> options() {
|
||||
Set<SocketOption<?>> options = new HashSet<>();
|
||||
if (flowSupported) {
|
||||
options.add(SO_FLOW_SLA);
|
||||
}
|
||||
if (quickAckSupported) {
|
||||
options.add(TCP_QUICKACK);
|
||||
}
|
||||
@ -242,11 +224,7 @@ public final class ExtendedSocketOptions {
|
||||
if (fd == null || !fd.valid())
|
||||
throw new SocketException("socket closed");
|
||||
|
||||
if (option == SO_FLOW_SLA) {
|
||||
assert flowSupported;
|
||||
SocketFlow flow = checkValueType(value, SocketFlow.class);
|
||||
setFlowOption(fd, flow);
|
||||
} else if (option == TCP_QUICKACK) {
|
||||
if (option == TCP_QUICKACK) {
|
||||
setQuickAckOption(fd, (boolean) value);
|
||||
} else if (option == TCP_KEEPCOUNT) {
|
||||
setTcpkeepAliveProbes(fd, (Integer) value);
|
||||
@ -277,12 +255,7 @@ public final class ExtendedSocketOptions {
|
||||
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 if (option == TCP_QUICKACK) {
|
||||
if (option == TCP_QUICKACK) {
|
||||
return getQuickAckOption(fd);
|
||||
} else if (option == TCP_KEEPCOUNT) {
|
||||
return getTcpkeepAliveProbes(fd);
|
||||
@ -299,35 +272,9 @@ public final class ExtendedSocketOptions {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T checkValueType(Object value, Class<T> type) {
|
||||
if (!type.isAssignableFrom(value.getClass())) {
|
||||
String s = "Found: " + value.getClass() + ", Expected: " + type;
|
||||
throw new IllegalArgumentException(s);
|
||||
}
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
private static final JavaIOFileDescriptorAccess fdAccess =
|
||||
SharedSecrets.getJavaIOFileDescriptorAccess();
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void setFlowOption(FileDescriptor fd, SocketFlow f)
|
||||
throws SocketException
|
||||
{
|
||||
int status = platformSocketOptions.setFlowOption(fdAccess.get(fd),
|
||||
f.priority(),
|
||||
f.bandwidth());
|
||||
f.status(status); // augment the given flow with the status
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void getFlowOption(FileDescriptor fd, SocketFlow f)
|
||||
throws SocketException {
|
||||
int status = platformSocketOptions.getFlowOption(fdAccess.get(fd), f);
|
||||
f.status(status); // augment the given flow with the status
|
||||
}
|
||||
|
||||
private static void setQuickAckOption(FileDescriptor fd, boolean enable)
|
||||
throws SocketException {
|
||||
platformSocketOptions.setQuickAck(fdAccess.get(fd), enable);
|
||||
@ -406,21 +353,6 @@ public final class ExtendedSocketOptions {
|
||||
return instance;
|
||||
}
|
||||
|
||||
int setFlowOption(int fd, int priority, long bandwidth)
|
||||
throws SocketException
|
||||
{
|
||||
throw new UnsupportedOperationException("unsupported socket option");
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
int getFlowOption(int fd, SocketFlow f) throws SocketException {
|
||||
throw new UnsupportedOperationException("unsupported socket option");
|
||||
}
|
||||
|
||||
boolean flowSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void setQuickAck(int fd, boolean on) throws SocketException {
|
||||
throw new UnsupportedOperationException("unsupported TCP_QUICKACK option");
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020, 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
|
||||
@ -31,36 +31,6 @@ import java.security.BasicPermission;
|
||||
* Represents permission to access the extended networking capabilities
|
||||
* defined in the jdk.net package. These permissions contain a target
|
||||
* name, but no actions list. Callers either possess the permission or not.
|
||||
* <p>
|
||||
* The following targets are defined:
|
||||
*
|
||||
* <table class="striped"><caption style="display:none">permission target name,
|
||||
* what the target allows,and associated risks</caption>
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th scope="col">Permission Target Name</th>
|
||||
* <th scope="col">What the Permission Allows</th>
|
||||
* <th scope="col">Risks of Allowing this Permission</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th scope="row">setOption.SO_FLOW_SLA</th>
|
||||
* <td>set the {@link ExtendedSocketOptions#SO_FLOW_SLA SO_FLOW_SLA} option
|
||||
* on any socket that supports it</td>
|
||||
* <td>allows caller to set a higher priority or bandwidth allocation
|
||||
* to sockets it creates, than they might otherwise be allowed.
|
||||
* This permission is deprecated.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th scope="row">getOption.SO_FLOW_SLA</th>
|
||||
* <td>retrieve the {@link ExtendedSocketOptions#SO_FLOW_SLA SO_FLOW_SLA}
|
||||
* setting from any socket that supports the option</td>
|
||||
* <td>allows caller access to SLA information that it might not
|
||||
* otherwise have. This permission is deprecated.</td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*
|
||||
* @see jdk.net.ExtendedSocketOptions
|
||||
*
|
||||
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.net;
|
||||
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
/**
|
||||
* Represents the service level properties for the platform specific socket
|
||||
* option {@link ExtendedSocketOptions#SO_FLOW_SLA}.
|
||||
* <p>
|
||||
* The priority and bandwidth parameters must be set before
|
||||
* setting the socket option.
|
||||
* <p>
|
||||
* When the {@code SO_FLOW_SLA} option is set then it may not take effect
|
||||
* immediately. If the value of the socket option is obtained with
|
||||
* {@code getOption()} then the status may be returned as {@code INPROGRESS}
|
||||
* until it takes effect. The priority and bandwidth values are only valid when
|
||||
* the status is returned as OK.
|
||||
* <p>
|
||||
* When a security manager is installed, a {@link NetworkPermission}
|
||||
* is required to set or get this option.
|
||||
*
|
||||
* @deprecated This is supported only on Solaris. Due to deprecation
|
||||
* of Solaris port, this feature is also deprecated.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@Deprecated(since="14", forRemoval=true)
|
||||
public class SocketFlow {
|
||||
|
||||
@Native public static final int UNSET = -1;
|
||||
@Native public static final int NORMAL_PRIORITY = 1;
|
||||
@Native public static final int HIGH_PRIORITY = 2;
|
||||
|
||||
@Native private static final int NO_STATUS_VALUE = 0;
|
||||
@Native private static final int OK_VALUE = 1;
|
||||
@Native private static final int NO_PERMISSION_VALUE = 2;
|
||||
@Native private static final int NOT_CONNECTED_VALUE = 3;
|
||||
@Native private static final int NOT_SUPPORTED_VALUE = 4;
|
||||
@Native private static final int ALREADY_CREATED_VALUE = 5;
|
||||
@Native private static final int IN_PROGRESS_VALUE = 6;
|
||||
@Native private static final int OTHER_VALUE = 7;
|
||||
|
||||
/**
|
||||
* Enumeration of the return values from the SO_FLOW_SLA
|
||||
* socket option. Both setting and getting the option return
|
||||
* one of these statuses, which reflect the state of socket's
|
||||
* flow.
|
||||
* @deprecated This is supported only on Solaris. Due to
|
||||
* deprecation of Solaris port, this enum is also deprecated.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since="14", forRemoval=true)
|
||||
public enum Status {
|
||||
/**
|
||||
* Set or get socket option has not been called yet. Status
|
||||
* values can only be retrieved after calling set or get.
|
||||
*/
|
||||
NO_STATUS(NO_STATUS_VALUE),
|
||||
/**
|
||||
* Flow successfully created.
|
||||
*/
|
||||
OK(OK_VALUE),
|
||||
/**
|
||||
* Caller has no permission to create flow.
|
||||
*/
|
||||
NO_PERMISSION(NO_PERMISSION_VALUE),
|
||||
/**
|
||||
* Flow can not be created because socket is not connected.
|
||||
*/
|
||||
NOT_CONNECTED(NOT_CONNECTED_VALUE),
|
||||
/**
|
||||
* Flow creation not supported for this socket.
|
||||
*/
|
||||
NOT_SUPPORTED(NOT_SUPPORTED_VALUE),
|
||||
/**
|
||||
* A flow already exists with identical attributes.
|
||||
*/
|
||||
ALREADY_CREATED(ALREADY_CREATED_VALUE),
|
||||
/**
|
||||
* A flow is being created.
|
||||
*/
|
||||
IN_PROGRESS(IN_PROGRESS_VALUE),
|
||||
/**
|
||||
* Some other unspecified error.
|
||||
*/
|
||||
OTHER(OTHER_VALUE);
|
||||
|
||||
private final int value;
|
||||
Status(int value) { this.value = value; }
|
||||
|
||||
static Status from(int value) {
|
||||
if (value == NO_STATUS.value) return NO_STATUS;
|
||||
else if (value == OK.value) return OK;
|
||||
else if (value == NO_PERMISSION.value) return NO_PERMISSION;
|
||||
else if (value == NOT_CONNECTED.value) return NOT_CONNECTED;
|
||||
else if (value == NOT_SUPPORTED.value) return NOT_SUPPORTED;
|
||||
else if (value == ALREADY_CREATED.value) return ALREADY_CREATED;
|
||||
else if (value == IN_PROGRESS.value) return IN_PROGRESS;
|
||||
else if (value == OTHER.value) return OTHER;
|
||||
else throw new InternalError("Unknown value: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private int priority = NORMAL_PRIORITY;
|
||||
private long bandwidth = UNSET;
|
||||
private Status status = Status.NO_STATUS;
|
||||
|
||||
/**
|
||||
* Creates a new SocketFlow that can be used to set the SO_FLOW_SLA
|
||||
* socket option and create a socket flow.
|
||||
*/
|
||||
public static SocketFlow create() {
|
||||
return new SocketFlow();
|
||||
}
|
||||
|
||||
private SocketFlow() { }
|
||||
|
||||
/**
|
||||
* Sets this SocketFlow's priority. Must be either NORMAL_PRIORITY
|
||||
* HIGH_PRIORITY. If not set, a flow's priority is normal.
|
||||
*
|
||||
* @throws IllegalArgumentException if priority is not NORMAL_PRIORITY or
|
||||
* HIGH_PRIORITY.
|
||||
*/
|
||||
public SocketFlow priority(int priority) {
|
||||
if (priority != NORMAL_PRIORITY && priority != HIGH_PRIORITY)
|
||||
throw new IllegalArgumentException("invalid priority :" + priority);
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this SocketFlow's bandwidth. Must be greater than or equal to zero.
|
||||
* A value of zero drops all packets for the socket.
|
||||
*
|
||||
* @throws IllegalArgumentException if bandwidth is less than zero.
|
||||
*/
|
||||
public SocketFlow bandwidth(long bandwidth) {
|
||||
if (bandwidth < 0)
|
||||
throw new IllegalArgumentException("invalid bandwidth: " + bandwidth);
|
||||
this.bandwidth = bandwidth;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this SocketFlow's priority.
|
||||
*/
|
||||
public int priority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this SocketFlow's bandwidth.
|
||||
*
|
||||
* @return this SocketFlow's bandwidth, or {@code -1} if status is not OK.
|
||||
*/
|
||||
public long bandwidth() {
|
||||
return bandwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Status value of this SocketFlow. NO_STATUS is returned
|
||||
* if the object was not used in a call to set or get the option.
|
||||
*/
|
||||
public Status status() {
|
||||
return status;
|
||||
}
|
||||
|
||||
void status(int status) {
|
||||
this.status = Status.from(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(super.toString());
|
||||
sb.append(" [ priority=").append(priority())
|
||||
.append(", bandwidth=").append(bandwidth())
|
||||
.append(", status=").append(status())
|
||||
.append(" ]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, 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
|
||||
@ -262,7 +262,6 @@ public class Sockets {
|
||||
@SuppressWarnings("removal")
|
||||
private static Map<Class<?>,Set<SocketOption<?>>> optionSets() {
|
||||
Map<Class<?>,Set<SocketOption<?>>> options = new HashMap<>();
|
||||
boolean flowsupported = PlatformSocketOptions.get().flowSupported();
|
||||
boolean incomingNapiIdsupported = PlatformSocketOptions.get().incomingNapiIdSupported();
|
||||
|
||||
boolean reuseportsupported = isReusePortAvailable();
|
||||
@ -279,9 +278,6 @@ public class Sockets {
|
||||
set.add(StandardSocketOptions.SO_LINGER);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
set.add(StandardSocketOptions.TCP_NODELAY);
|
||||
if (flowsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
}
|
||||
if (QuickAck.available) {
|
||||
set.add(ExtendedSocketOptions.TCP_QUICKACK);
|
||||
}
|
||||
@ -329,9 +325,6 @@ public class Sockets {
|
||||
set.add(StandardSocketOptions.SO_REUSEPORT);
|
||||
}
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
if (flowsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
}
|
||||
if (incomingNapiIdsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_INCOMING_NAPI_ID);
|
||||
}
|
||||
@ -351,9 +344,6 @@ public class Sockets {
|
||||
set.add(StandardSocketOptions.IP_MULTICAST_IF);
|
||||
set.add(StandardSocketOptions.IP_MULTICAST_TTL);
|
||||
set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
|
||||
if (flowsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
}
|
||||
set = Collections.unmodifiableSet(set);
|
||||
options.put(MulticastSocket.class, set);
|
||||
|
||||
|
@ -58,7 +58,6 @@ public class LoadLibraryTest {
|
||||
// jdk/jdk: loads directly from Bootstrap Classloader (doesn't take lock on Runtime)
|
||||
java.net.NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
System.out.println(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
*/
|
||||
Class c = Class.forName("Target2", true, loader);
|
||||
} catch (Exception e) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020, 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
|
||||
@ -97,9 +97,7 @@ public class AfterClose {
|
||||
// extended options
|
||||
try {
|
||||
Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions");
|
||||
Field field = c.getField("SO_FLOW_SLA");
|
||||
map.put((SocketOption<?>)field.get(null), listOf(createSocketFlow()));
|
||||
field = c.getField("TCP_QUICKACK");
|
||||
Field field = c.getField("TCP_QUICKACK");
|
||||
map.put((SocketOption<?>)field.get(null), listOf(TRUE, FALSE));
|
||||
field = c.getField("TCP_KEEPIDLE");
|
||||
map.put((SocketOption<?>)field.get(null), listOf(10, 100));
|
||||
@ -397,14 +395,4 @@ public class AfterClose {
|
||||
ms.close();
|
||||
return ms;
|
||||
}
|
||||
|
||||
static Object createSocketFlow() {
|
||||
try {
|
||||
Class<?> c = Class.forName("jdk.net.SocketFlow");
|
||||
Method method = c.getDeclaredMethod("create");
|
||||
return method.invoke(null);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, 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
|
||||
@ -60,9 +60,7 @@ public class UnsupportedOptionsTest {
|
||||
|
||||
try {
|
||||
Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions");
|
||||
Field field = c.getField("SO_FLOW_SLA");
|
||||
socketOptions.add((SocketOption<?>)field.get(null));
|
||||
field = c.getField("TCP_QUICKACK");
|
||||
Field field = c.getField("TCP_QUICKACK");
|
||||
socketOptions.add((SocketOption<?>)field.get(null));
|
||||
field = c.getField("TCP_KEEPIDLE");
|
||||
socketOptions.add((SocketOption<?>)field.get(null));
|
||||
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8765432
|
||||
* @summary Basic test for SocketFlow API
|
||||
* @modules jdk.net
|
||||
* @run testng SocketFlowBasic
|
||||
*/
|
||||
|
||||
import jdk.net.SocketFlow;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static jdk.net.SocketFlow.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SocketFlowBasic {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] validPriorities() {
|
||||
return new Object[][] { {HIGH_PRIORITY}, {NORMAL_PRIORITY} };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "validPriorities")
|
||||
public void priority(long validPriority) {
|
||||
SocketFlow flow = SocketFlow.create();
|
||||
flow.bandwidth(validPriority);
|
||||
long bandwidth = flow.bandwidth();
|
||||
assertTrue(bandwidth == validPriority, "Expected " + validPriority + ", got" + bandwidth);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] invalidPriorities() {
|
||||
return new Object[][] { {HIGH_PRIORITY+10}, {NORMAL_PRIORITY-10000} };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "invalidPriorities", expectedExceptions = IllegalArgumentException.class)
|
||||
public void priority(int invalidPriority) {
|
||||
SocketFlow flow = SocketFlow.create();
|
||||
flow.priority(invalidPriority);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] positiveBandwidth() {
|
||||
return new Object[][] { {0}, {100}, {Integer.MAX_VALUE}, {Long.MAX_VALUE} };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "positiveBandwidth")
|
||||
public void bandwidth(long posBandwidth) {
|
||||
SocketFlow flow = SocketFlow.create();
|
||||
flow.bandwidth(posBandwidth);
|
||||
long bandwidth = flow.bandwidth();
|
||||
assertTrue(bandwidth == posBandwidth, "Expected " + posBandwidth + ", got" + bandwidth);
|
||||
}
|
||||
|
||||
|
||||
@DataProvider
|
||||
public Object[][] negativeBandwidth() {
|
||||
return new Object[][] { {-1}, {-100}, {Integer.MIN_VALUE}, {Long.MIN_VALUE} };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "negativeBandwidth", expectedExceptions = IllegalArgumentException.class)
|
||||
public void invalidBandwidth(long negBandwidth) {
|
||||
SocketFlow flow = SocketFlow.create();
|
||||
flow.bandwidth(negBandwidth);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void status() {
|
||||
SocketFlow flow = SocketFlow.create();
|
||||
assertTrue(flow.status() == Status.NO_STATUS);
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
import static jdk.net.ExtendedSocketOptions.TCP_QUICKACK;
|
||||
import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
|
||||
|
||||
public class ExtOptionTest {
|
||||
|
||||
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2020, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8032808 8044773
|
||||
* @modules jdk.net
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.OSVersion jdk.test.lib.Platform
|
||||
* @run main/othervm -Xcheck:jni Test success
|
||||
* @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
|
||||
* @run main/othervm/policy=policy.success -Xcheck:jni Test success
|
||||
*/
|
||||
|
||||
import jdk.net.SocketFlow;
|
||||
import jdk.net.Sockets;
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.OSVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.nio.channels.AsynchronousSocketChannel;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static java.lang.System.out;
|
||||
import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
|
||||
|
||||
public class Test {
|
||||
|
||||
interface Runner { void run() throws Exception; }
|
||||
|
||||
static boolean expectSuccess;
|
||||
private static final boolean expectSupport = checkExpectedOptionSupport();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// quick check to see if supportedOptions() working before
|
||||
// creating any sockets and libnet loaded
|
||||
|
||||
Sockets.supportedOptions(Socket.class);
|
||||
|
||||
expectSuccess = args[0].equals("success");
|
||||
|
||||
// Main thing is to check for JNI problems
|
||||
// Doesn't matter if currently setting the option with the loopback
|
||||
// interface doesn't work
|
||||
|
||||
boolean sm = System.getSecurityManager() != null;
|
||||
out.println("Security Manager enabled: " + sm);
|
||||
out.println("Success expected: " + expectSuccess);
|
||||
|
||||
SocketFlow flowIn = SocketFlow.create()
|
||||
.bandwidth(1000)
|
||||
.priority(SocketFlow.HIGH_PRIORITY);
|
||||
|
||||
try (ServerSocket ss = new ServerSocket(0);
|
||||
DatagramSocket dg = new DatagramSocket(0)) {
|
||||
|
||||
int tcp_port = ss.getLocalPort();
|
||||
final InetAddress loop = InetAddress.getLoopbackAddress();
|
||||
final InetSocketAddress loopad = new InetSocketAddress(loop, tcp_port);
|
||||
|
||||
final int udp_port = dg.getLocalPort();
|
||||
|
||||
final Socket s = new Socket(loop, tcp_port);
|
||||
final SocketChannel sc = SocketChannel.open();
|
||||
sc.connect(new InetSocketAddress(loop, tcp_port));
|
||||
|
||||
doTest("Sockets.setOption Socket", () -> {
|
||||
out.println(flowIn);
|
||||
if (s.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
Sockets.setOption(s, SO_FLOW_SLA, flowIn);
|
||||
out.println(flowIn);
|
||||
});
|
||||
|
||||
doTest("Sockets.getOption Socket", () -> {
|
||||
Sockets.getOption(s, SO_FLOW_SLA);
|
||||
out.println(flowIn);
|
||||
});
|
||||
|
||||
doTest("Sockets.setOption SocketChannel", () -> {
|
||||
if (sc.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
sc.setOption(SO_FLOW_SLA, flowIn);
|
||||
});
|
||||
doTest("Sockets.getOption SocketChannel", () ->
|
||||
sc.getOption(SO_FLOW_SLA)
|
||||
);
|
||||
doTest("Sockets.setOption DatagramSocket", () -> {
|
||||
try (DatagramSocket dg1 = new DatagramSocket(0)) {
|
||||
if (dg1.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
|
||||
dg1.connect(loop, udp_port);
|
||||
Sockets.setOption(dg1, SO_FLOW_SLA, flowIn);
|
||||
}
|
||||
});
|
||||
doTest("Sockets.setOption DatagramSocket 2", () -> {
|
||||
try (DatagramChannel dg2 = DatagramChannel.open()) {
|
||||
if (dg2.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
dg2.bind(new InetSocketAddress(loop, 0));
|
||||
dg2.connect(new InetSocketAddress(loop, udp_port));
|
||||
dg2.setOption(SO_FLOW_SLA, flowIn);
|
||||
}
|
||||
});
|
||||
doTest("Sockets.setOption MulticastSocket", () -> {
|
||||
try (MulticastSocket mc1 = new MulticastSocket(0)) {
|
||||
if (mc1.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
mc1.connect(loop, udp_port);
|
||||
Sockets.setOption(mc1, SO_FLOW_SLA, flowIn);
|
||||
}
|
||||
});
|
||||
doTest("Sockets.setOption AsynchronousSocketChannel", () -> {
|
||||
try (AsynchronousSocketChannel asc = AsynchronousSocketChannel.open()) {
|
||||
if (asc.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||
throw new RuntimeException("Unexpected supportedOptions()");
|
||||
}
|
||||
Future<Void> f = asc.connect(loopad);
|
||||
f.get();
|
||||
asc.setOption(SO_FLOW_SLA, flowIn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void doTest(String message, Runner func) throws Exception {
|
||||
out.println(message);
|
||||
try {
|
||||
func.run();
|
||||
if (expectSuccess) {
|
||||
out.println("Completed as expected");
|
||||
} else {
|
||||
throw new RuntimeException("Operation succeeded, but expected SecurityException");
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
if (expectSuccess) {
|
||||
throw new RuntimeException("Unexpected SecurityException", e);
|
||||
} else {
|
||||
out.println("Caught expected: " + e);
|
||||
return;
|
||||
}
|
||||
} catch (UnsupportedOperationException e) {
|
||||
if (expectSupport) {
|
||||
throw new RuntimeException("Test failed: " +
|
||||
"unexpected UnsupportedOperationException");
|
||||
}
|
||||
out.println("UnsupportedOperationException as expected");
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
// Probably a permission error, but we're not
|
||||
// going to check unless a specific permission exception
|
||||
// is defined.
|
||||
System.out.println(e);
|
||||
}
|
||||
if (!expectSupport) {
|
||||
throw new RuntimeException("Test failed: " +
|
||||
"UnsupportedOperationException was not thrown");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkExpectedOptionSupport() {
|
||||
System.out.println("SO_FLOW_SLA should not be supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
grant codeBase "file:${test.classes}/../../../../test/lib/-" {
|
||||
permission java.util.PropertyPermission "*", "read";
|
||||
permission java.io.FilePermission "/etc/release", "read";
|
||||
permission java.io.FilePermission "<<ALL FILES>>", "execute";
|
||||
};
|
||||
|
||||
grant codeBase "file:${test.classes}/*" {
|
||||
permission java.net.SocketPermission "127.0.0.1", "connect,accept";
|
||||
permission java.net.SocketPermission "localhost", "listen";
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
grant codeBase "file:${test.classes}/../../../../test/lib/-" {
|
||||
permission java.util.PropertyPermission "*", "read";
|
||||
permission java.io.FilePermission "/etc/release", "read";
|
||||
permission java.io.FilePermission "<<ALL FILES>>", "execute";
|
||||
};
|
||||
|
||||
grant codeBase "file:${test.classes}/*" {
|
||||
permission java.net.SocketPermission "127.0.0.1", "connect,accept";
|
||||
permission java.net.SocketPermission "localhost", "listen";
|
||||
permission jdk.net.NetworkPermission "setOption.SO_FLOW_SLA";
|
||||
permission jdk.net.NetworkPermission "getOption.SO_FLOW_SLA";
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2020, 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
|
||||
@ -61,8 +61,6 @@ public class Modules {
|
||||
new javax.security.auth.AuthPermission("doAsPrivileged"),
|
||||
new javax.security.auth.PrivateCredentialPermission("* * \"*\"",
|
||||
"read"),
|
||||
// java.base module (@jdk.Exported Permissions)
|
||||
new jdk.net.NetworkPermission("setOption.SO_FLOW_SLA"),
|
||||
// java.desktop module
|
||||
new java.awt.AWTPermission("createRobot"),
|
||||
new javax.sound.sampled.AudioPermission("play"),
|
||||
|
@ -7,8 +7,6 @@ grant {
|
||||
permission javax.security.auth.AuthPermission "doAsPrivileged";
|
||||
permission javax.security.auth.PrivateCredentialPermission "* * \"*\"",
|
||||
"read";
|
||||
// java.base module (@jdk.Exported Permissions)
|
||||
permission jdk.net.NetworkPermission "setOption.SO_FLOW_SLA";
|
||||
// java.desktop module
|
||||
permission java.awt.AWTPermission "createRobot";
|
||||
permission javax.sound.sampled.AudioPermission "play";
|
||||
|
Loading…
Reference in New Issue
Block a user