feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
122
jdkSrc/jdk8/jdk/net/ExtendedSocketOptions.java
Normal file
122
jdkSrc/jdk8/jdk/net/ExtendedSocketOptions.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2018, 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.net.SocketOption;
|
||||
|
||||
/**
|
||||
* Defines extended socket options, beyond those defined in
|
||||
* {@link java.net.StandardSocketOptions}. These options may be platform
|
||||
* specific.
|
||||
*/
|
||||
@jdk.Exported
|
||||
public final class ExtendedSocketOptions {
|
||||
|
||||
private static class ExtSocketOption<T> implements SocketOption<T> {
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
ExtSocketOption(String name, Class<T> type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
@Override public String name() { return name; }
|
||||
@Override public Class<T> type() { return type; }
|
||||
@Override public String toString() { return name; }
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
public static final SocketOption<SocketFlow> SO_FLOW_SLA = new
|
||||
ExtSocketOption<SocketFlow>("SO_FLOW_SLA", SocketFlow.class);
|
||||
|
||||
/**
|
||||
* Keep-Alive idle time.
|
||||
*
|
||||
* <p>
|
||||
* The value of this socket option is an {@code Integer} that is the number
|
||||
* of seconds of idle time before keep-alive initiates a probe. The socket
|
||||
* option is specific to stream-oriented sockets using the TCP/IP protocol.
|
||||
* The exact semantics of this socket option are system dependent.
|
||||
*
|
||||
* <p>
|
||||
* When the {@link java.net.StandardSocketOptions#SO_KEEPALIVE
|
||||
* SO_KEEPALIVE} option is enabled, TCP probes a connection that has been
|
||||
* idle for some amount of time. The default value for this idle period is
|
||||
* system dependent, but is typically 2 hours. The {@code TCP_KEEPIDLE}
|
||||
* option can be used to affect this value for a given socket.
|
||||
*/
|
||||
public static final SocketOption<Integer> TCP_KEEPIDLE
|
||||
= new ExtSocketOption<Integer>("TCP_KEEPIDLE", Integer.class);
|
||||
|
||||
/**
|
||||
* Keep-Alive retransmission interval time.
|
||||
*
|
||||
* <p>
|
||||
* The value of this socket option is an {@code Integer} that is the number
|
||||
* of seconds to wait before retransmitting a keep-alive probe. The socket
|
||||
* option is specific to stream-oriented sockets using the TCP/IP protocol.
|
||||
* The exact semantics of this socket option are system dependent.
|
||||
*
|
||||
* <p>
|
||||
* When the {@link java.net.StandardSocketOptions#SO_KEEPALIVE
|
||||
* SO_KEEPALIVE} option is enabled, TCP probes a connection that has been
|
||||
* idle for some amount of time. If the remote system does not respond to a
|
||||
* keep-alive probe, TCP retransmits the probe after some amount of time.
|
||||
* The default value for this retransmission interval is system dependent,
|
||||
* but is typically 75 seconds. The {@code TCP_KEEPINTERVAL} option can be
|
||||
* used to affect this value for a given socket.
|
||||
*/
|
||||
public static final SocketOption<Integer> TCP_KEEPINTERVAL
|
||||
= new ExtSocketOption<Integer>("TCP_KEEPINTERVAL", Integer.class);
|
||||
|
||||
/**
|
||||
* Keep-Alive retransmission maximum limit.
|
||||
*
|
||||
* <p>
|
||||
* The value of this socket option is an {@code Integer} that is the maximum
|
||||
* number of keep-alive probes to be sent. The socket option is specific to
|
||||
* stream-oriented sockets using the TCP/IP protocol. The exact semantics of
|
||||
* this socket option are system dependent.
|
||||
*
|
||||
* <p>
|
||||
* When the {@link java.net.StandardSocketOptions#SO_KEEPALIVE
|
||||
* SO_KEEPALIVE} option is enabled, TCP probes a connection that has been
|
||||
* idle for some amount of time. If the remote system does not respond to a
|
||||
* keep-alive probe, TCP retransmits the probe a certain number of times
|
||||
* before a connection is considered to be broken. The default value for
|
||||
* this keep-alive probe retransmit limit is system dependent, but is
|
||||
* typically 8. The {@code TCP_KEEPCOUNT} option can be used to affect this
|
||||
* value for a given socket.
|
||||
*/
|
||||
public static final SocketOption<Integer> TCP_KEEPCOUNT
|
||||
= new ExtSocketOption<Integer>("TCP_KEEPCOUNT", Integer.class);
|
||||
}
|
||||
89
jdkSrc/jdk8/jdk/net/NetworkPermission.java
Normal file
89
jdkSrc/jdk8/jdk/net/NetworkPermission.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.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:
|
||||
* <p>
|
||||
* <table border=1 cellpadding=5 summary="permission target name,
|
||||
* what the target allows,and associated risks">
|
||||
* <tr>
|
||||
* <th>Permission Target Name</th>
|
||||
* <th>What the Permission Allows</th>
|
||||
* <th>Risks of Allowing this Permission</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>setOption.SO_FLOW_SLA</td>
|
||||
* <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.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>getOption.SO_FLOW_SLA</td>
|
||||
* <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</td>
|
||||
* </tr></table>
|
||||
*
|
||||
* @see jdk.net.ExtendedSocketOptions
|
||||
*/
|
||||
|
||||
@jdk.Exported
|
||||
public final class NetworkPermission extends BasicPermission {
|
||||
|
||||
private static final long serialVersionUID = -2012939586906722291L;
|
||||
|
||||
/**
|
||||
* Creates a NetworkPermission with the given target name.
|
||||
*
|
||||
* @param name the permission target name
|
||||
* @throws NullPointerException if {@code name} is {@code null}.
|
||||
* @throws IllegalArgumentException if {@code name} is empty.
|
||||
*/
|
||||
public NetworkPermission(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a NetworkPermission with the given target name.
|
||||
*
|
||||
* @param name the permission target name
|
||||
* @param actions should be {@code null}. Is ignored if not.
|
||||
* @throws NullPointerException if {@code name} is {@code null}.
|
||||
* @throws IllegalArgumentException if {@code name} is empty.
|
||||
*/
|
||||
public NetworkPermission(String name, String actions) {
|
||||
super(name, actions);
|
||||
}
|
||||
}
|
||||
165
jdkSrc/jdk8/jdk/net/SocketFlow.java
Normal file
165
jdkSrc/jdk8/jdk/net/SocketFlow.java
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class SocketFlow {
|
||||
|
||||
private static final int UNSET = -1;
|
||||
@Native public static final int NORMAL_PRIORITY = 1;
|
||||
@Native public static final int HIGH_PRIORITY = 2;
|
||||
|
||||
private int priority = NORMAL_PRIORITY;
|
||||
|
||||
private long bandwidth = UNSET;
|
||||
|
||||
private Status status = Status.NO_STATUS;
|
||||
|
||||
private SocketFlow() {}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@jdk.Exported
|
||||
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,
|
||||
/**
|
||||
* Flow successfully created.
|
||||
*/
|
||||
OK,
|
||||
/**
|
||||
* Caller has no permission to create flow.
|
||||
*/
|
||||
NO_PERMISSION,
|
||||
/**
|
||||
* Flow can not be created because socket is not connected.
|
||||
*/
|
||||
NOT_CONNECTED,
|
||||
/**
|
||||
* Flow creation not supported for this socket.
|
||||
*/
|
||||
NOT_SUPPORTED,
|
||||
/**
|
||||
* A flow already exists with identical attributes.
|
||||
*/
|
||||
ALREADY_CREATED,
|
||||
/**
|
||||
* A flow is being created.
|
||||
*/
|
||||
IN_PROGRESS,
|
||||
/**
|
||||
* Some other unspecified error.
|
||||
*/
|
||||
OTHER
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
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");
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
411
jdkSrc/jdk8/jdk/net/Sockets.java
Normal file
411
jdkSrc/jdk8/jdk/net/Sockets.java
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2018, 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.net.*;
|
||||
import java.io.IOException;
|
||||
import java.io.FileDescriptor;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.AccessController;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import sun.net.ExtendedOptionsImpl;
|
||||
import sun.net.ExtendedOptionsHelper;
|
||||
|
||||
/**
|
||||
* Defines static methods to set and get socket options defined by the
|
||||
* {@link java.net.SocketOption} interface. All of the standard options defined
|
||||
* by {@link java.net.Socket}, {@link java.net.ServerSocket}, and
|
||||
* {@link java.net.DatagramSocket} can be set this way, as well as additional
|
||||
* or platform specific options supported by each socket type.
|
||||
* <p>
|
||||
* The {@link #supportedOptions(Class)} method can be called to determine
|
||||
* the complete set of options available (per socket type) on the
|
||||
* current system.
|
||||
* <p>
|
||||
* When a security manager is installed, some non-standard socket options
|
||||
* may require a security permission before being set or get.
|
||||
* The details are specified in {@link ExtendedSocketOptions}. No permission
|
||||
* is required for {@link java.net.StandardSocketOptions}.
|
||||
*
|
||||
* @see java.nio.channels.NetworkChannel
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class Sockets {
|
||||
|
||||
private final static HashMap<Class<?>,Set<SocketOption<?>>>
|
||||
options = new HashMap<>();
|
||||
|
||||
static {
|
||||
initOptionSets();
|
||||
AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
initMethods();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static Method siSetOption;
|
||||
private static Method siGetOption;
|
||||
private static Method dsiSetOption;
|
||||
private static Method dsiGetOption;
|
||||
|
||||
private static void initMethods() {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("java.net.SocketSecrets");
|
||||
|
||||
siSetOption = clazz.getDeclaredMethod(
|
||||
"setOption", Object.class,
|
||||
SocketOption.class, Object.class
|
||||
);
|
||||
siSetOption.setAccessible(true);
|
||||
|
||||
siGetOption = clazz.getDeclaredMethod(
|
||||
"getOption", Object.class, SocketOption.class
|
||||
);
|
||||
siGetOption.setAccessible(true);
|
||||
|
||||
dsiSetOption = clazz.getDeclaredMethod(
|
||||
"setOption", DatagramSocket.class,
|
||||
SocketOption.class, Object.class
|
||||
);
|
||||
dsiSetOption.setAccessible(true);
|
||||
|
||||
dsiGetOption = clazz.getDeclaredMethod(
|
||||
"getOption", DatagramSocket.class, SocketOption.class
|
||||
);
|
||||
dsiGetOption.setAccessible(true);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new InternalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void invokeSet(
|
||||
Method method, Object socket,
|
||||
SocketOption<T> option, T value) throws IOException
|
||||
{
|
||||
try {
|
||||
method.invoke(null, socket, option, value);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof InvocationTargetException) {
|
||||
Throwable t = ((InvocationTargetException)e).getTargetException();
|
||||
if (t instanceof IOException) {
|
||||
throw (IOException)t;
|
||||
} else if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException)t;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T invokeGet(
|
||||
Method method, Object socket, SocketOption<T> option) throws IOException
|
||||
{
|
||||
try {
|
||||
return (T)method.invoke(null, socket, option);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof InvocationTargetException) {
|
||||
Throwable t = ((InvocationTargetException)e).getTargetException();
|
||||
if (t instanceof IOException) {
|
||||
throw (IOException)t;
|
||||
} else if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException)t;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Sockets() {}
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option on a {@link java.net.Socket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
* @param value The value of the socket option. May be null for some
|
||||
* options.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IllegalArgumentException if the value is not valid for
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs, or socket is closed.
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException
|
||||
{
|
||||
if (!isSupported(Socket.class, name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
invokeSet(siSetOption, s, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option from a {@link java.net.Socket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
*
|
||||
* @return The value of the socket option.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
|
||||
{
|
||||
if (!isSupported(Socket.class, name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
return invokeGet(siGetOption, s, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option on a {@link java.net.ServerSocket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
* @param value The value of the socket option.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IllegalArgumentException if the value is not valid for
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException
|
||||
{
|
||||
if (!isSupported(ServerSocket.class, name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
invokeSet(siSetOption, s, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option from a {@link java.net.ServerSocket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
*
|
||||
* @return The value of the socket option.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException
|
||||
{
|
||||
if (!isSupported(ServerSocket.class, name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
return invokeGet(siGetOption, s, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option on a {@link java.net.DatagramSocket}
|
||||
* or {@link java.net.MulticastSocket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
* @param value The value of the socket option.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IllegalArgumentException if the value is not valid for
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException
|
||||
{
|
||||
if (!isSupported(s.getClass(), name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
invokeSet(dsiSetOption, s, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option from a
|
||||
* {@link java.net.DatagramSocket} or {@link java.net.MulticastSocket}
|
||||
*
|
||||
* @param s the socket
|
||||
* @param name The socket option
|
||||
*
|
||||
* @return The value of the socket option.
|
||||
*
|
||||
* @throws UnsupportedOperationException if the socket does not support
|
||||
* the option.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs
|
||||
*
|
||||
* @throws NullPointerException if name is null
|
||||
*
|
||||
* @throws SecurityException if a security manager is set and the
|
||||
* caller does not have any required permission.
|
||||
*
|
||||
* @see java.net.StandardSocketOptions
|
||||
*/
|
||||
public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException
|
||||
{
|
||||
if (!isSupported(s.getClass(), name)) {
|
||||
throw new UnsupportedOperationException(name.name());
|
||||
}
|
||||
return invokeGet(dsiGetOption, s, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of {@link java.net.SocketOption}s supported by the
|
||||
* given socket type. This set may include standard options and also
|
||||
* non standard extended options.
|
||||
*
|
||||
* @param socketType the type of java.net socket
|
||||
*
|
||||
* @throws IllegalArgumentException if socketType is not a valid
|
||||
* socket type from the java.net package.
|
||||
*/
|
||||
public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) {
|
||||
Set<SocketOption<?>> set = options.get(socketType);
|
||||
if (set == null) {
|
||||
throw new IllegalArgumentException("unknown socket type");
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private static boolean isSupported(Class<?> type, SocketOption<?> option) {
|
||||
Set<SocketOption<?>> options = supportedOptions(type);
|
||||
return options.contains(option);
|
||||
}
|
||||
|
||||
private static void initOptionSets() {
|
||||
boolean flowsupported = ExtendedOptionsImpl.flowSupported();
|
||||
|
||||
// Socket
|
||||
|
||||
Set<SocketOption<?>> set = new HashSet<>();
|
||||
set.add(StandardSocketOptions.SO_KEEPALIVE);
|
||||
set.add(StandardSocketOptions.SO_SNDBUF);
|
||||
set.add(StandardSocketOptions.SO_RCVBUF);
|
||||
set.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
set.add(StandardSocketOptions.SO_LINGER);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
set.add(StandardSocketOptions.TCP_NODELAY);
|
||||
if (flowsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
}
|
||||
set.addAll(ExtendedOptionsHelper.keepAliveOptions());
|
||||
set = Collections.unmodifiableSet(set);
|
||||
options.put(Socket.class, set);
|
||||
|
||||
// ServerSocket
|
||||
|
||||
set = new HashSet<>();
|
||||
set.add(StandardSocketOptions.SO_RCVBUF);
|
||||
set.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
set.addAll(ExtendedOptionsHelper.keepAliveOptions());
|
||||
set = Collections.unmodifiableSet(set);
|
||||
options.put(ServerSocket.class, set);
|
||||
|
||||
// DatagramSocket
|
||||
|
||||
set = new HashSet<>();
|
||||
set.add(StandardSocketOptions.SO_SNDBUF);
|
||||
set.add(StandardSocketOptions.SO_RCVBUF);
|
||||
set.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
if (flowsupported) {
|
||||
set.add(ExtendedSocketOptions.SO_FLOW_SLA);
|
||||
}
|
||||
set = Collections.unmodifiableSet(set);
|
||||
options.put(DatagramSocket.class, set);
|
||||
|
||||
// MulticastSocket
|
||||
|
||||
set = new HashSet<>();
|
||||
set.add(StandardSocketOptions.SO_SNDBUF);
|
||||
set.add(StandardSocketOptions.SO_RCVBUF);
|
||||
set.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
set.add(StandardSocketOptions.IP_TOS);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
32
jdkSrc/jdk8/jdk/net/package-info.java
Normal file
32
jdkSrc/jdk8/jdk/net/package-info.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Platform specific socket options for the {@code java.net} and {@code java.nio.channels}
|
||||
* socket classes.
|
||||
*/
|
||||
|
||||
@jdk.Exported
|
||||
package jdk.net;
|
||||
Reference in New Issue
Block a user