Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/net/ExtendedOptionsImpl.java
38829 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.net;2627import java.net.*;28import jdk.net.*;29import java.io.IOException;30import java.io.FileDescriptor;31import java.security.PrivilegedAction;32import java.security.AccessController;33import java.lang.reflect.Field;34import java.util.Set;35import java.util.HashSet;36import java.util.HashMap;37import java.util.Collections;3839/**40* Contains the native implementation for extended socket options41* together with some other static utilities42*/43public class ExtendedOptionsImpl {4445static {46AccessController.doPrivileged((PrivilegedAction<Void>)() -> {47System.loadLibrary("net");48return null;49});50init();51}5253private ExtendedOptionsImpl() {}5455public static void checkSetOptionPermission(SocketOption<?> option) {56SecurityManager sm = System.getSecurityManager();57if (sm == null) {58return;59}60String check = "setOption." + option.name();61sm.checkPermission(new NetworkPermission(check));62}6364public static void checkGetOptionPermission(SocketOption<?> option) {65SecurityManager sm = System.getSecurityManager();66if (sm == null) {67return;68}69String check = "getOption." + option.name();70sm.checkPermission(new NetworkPermission(check));71}7273public static void checkValueType(Object value, Class<?> type) {74if (!type.isAssignableFrom(value.getClass())) {75String s = "Found: " + value.getClass().toString() + " Expected: "76+ type.toString();77throw new IllegalArgumentException(s);78}79}8081private static native void init();8283/*84* Extension native implementations85*86* SO_FLOW_SLA87*/88public static native void setFlowOption(FileDescriptor fd, SocketFlow f);89public static native void getFlowOption(FileDescriptor fd, SocketFlow f);90public static native boolean flowSupported();9192public static native void setTcpKeepAliveProbes(FileDescriptor fd, int value) throws SocketException;93public static native void setTcpKeepAliveTime(FileDescriptor fd, int value) throws SocketException;94public static native void setTcpKeepAliveIntvl(FileDescriptor fd, int value) throws SocketException;95public static native int getTcpKeepAliveProbes(FileDescriptor fd) throws SocketException;96public static native int getTcpKeepAliveTime(FileDescriptor fd) throws SocketException;97public static native int getTcpKeepAliveIntvl(FileDescriptor fd) throws SocketException;98public static native boolean keepAliveOptionsSupported();99}100101102