Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/java/net/PlainSocketImpl.java
32285 views
/*1* Copyright (c) 2007, 2008, 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*/24package java.net;2526import java.io.IOException;27import java.io.FileDescriptor;28import java.util.Set;29import java.util.HashSet;30import java.util.Collections;31import jdk.net.*;3233import sun.net.ExtendedOptionsImpl;3435/*36* On Unix systems we simply delegate to native methods.37*38* @author Chris Hegarty39*/4041class PlainSocketImpl extends AbstractPlainSocketImpl42{43static {44initProto();45}4647/**48* Constructs an empty instance.49*/50PlainSocketImpl() { }5152/**53* Constructs an instance with the given file descriptor.54*/55PlainSocketImpl(FileDescriptor fd) {56this.fd = fd;57}5859protected <T> void setOption(SocketOption<T> name, T value) throws IOException {60if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {61checkSetOption(name, value, SocketFlow.class);62ExtendedOptionsImpl.setFlowOption(getFileDescriptor(), (SocketFlow)value);63} else if (name == ExtendedSocketOptions.TCP_KEEPIDLE) {64checkSetOption(name, value, Integer.class);65ExtendedOptionsImpl.setTcpKeepAliveTime(getFileDescriptor(), (Integer)value);66} else if (name == ExtendedSocketOptions.TCP_KEEPINTERVAL) {67checkSetOption(name, value, Integer.class);68ExtendedOptionsImpl.setTcpKeepAliveIntvl(getFileDescriptor(), (Integer)value);69} else if (name == ExtendedSocketOptions.TCP_KEEPCOUNT) {70checkSetOption(name, value, Integer.class);71ExtendedOptionsImpl.setTcpKeepAliveProbes(getFileDescriptor(), (Integer)value);72} else {73super.setOption(name, value);74}75}7677private <T> void checkSetOption(SocketOption<T> name, T value, Class<?> expected) throws IOException {78if (isClosedOrPending()) {79throw new SocketException("Socket closed");80}81ExtendedOptionsImpl.checkSetOptionPermission(name);82ExtendedOptionsImpl.checkValueType(value, expected);83}8485private <T> void checkGetOption(SocketOption<T> name) throws IOException {86if (isClosedOrPending()) {87throw new SocketException("Socket closed");88}89ExtendedOptionsImpl.checkGetOptionPermission(name);90}9192protected <T> T getOption(SocketOption<T> name) throws IOException {93if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {94checkGetOption(name);95SocketFlow flow = SocketFlow.create();96ExtendedOptionsImpl.getFlowOption(getFileDescriptor(), flow);97return (T)flow;98} else if (name == ExtendedSocketOptions.TCP_KEEPIDLE) {99checkGetOption(name);100int retVal = ExtendedOptionsImpl.getTcpKeepAliveTime(getFileDescriptor());101return (T)Integer.valueOf(retVal);102} else if (name == ExtendedSocketOptions.TCP_KEEPINTERVAL) {103checkGetOption(name);104int retVal = ExtendedOptionsImpl.getTcpKeepAliveIntvl(getFileDescriptor());105return (T)Integer.valueOf(retVal);106} else if (name == ExtendedSocketOptions.TCP_KEEPCOUNT) {107checkGetOption(name);108int retVal = ExtendedOptionsImpl.getTcpKeepAliveProbes(getFileDescriptor());109return (T)Integer.valueOf(retVal);110} else {111return super.getOption(name);112}113}114115protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {116try {117socketSetOption0(opt, b, val);118} catch (SocketException se) {119if (socket == null || !socket.isConnected())120throw se;121}122}123124native void socketCreate(boolean isServer) throws IOException;125126native void socketConnect(InetAddress address, int port, int timeout)127throws IOException;128129native void socketBind(InetAddress address, int port)130throws IOException;131132native void socketListen(int count) throws IOException;133134native void socketAccept(SocketImpl s) throws IOException;135136native int socketAvailable() throws IOException;137138native void socketClose0(boolean useDeferredClose) throws IOException;139140native void socketShutdown(int howto) throws IOException;141142static native void initProto();143144native void socketSetOption0(int cmd, boolean on, Object value)145throws SocketException;146147native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;148149native void socketSendUrgentData(int data) throws IOException;150}151152153