Path: blob/master/src/java.base/unix/classes/sun/net/NetHooks.java
41133 views
/*1* Copyright (c) 2009, 2010, 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.InetAddress;28import java.io.FileDescriptor;29import java.io.IOException;3031/**32* Defines static methods to be invoked prior to binding or connecting TCP sockets.33*/3435public final class NetHooks {3637/**38* A provider with hooks to allow sockets be converted prior to binding or39* connecting a TCP socket.40*41* <p> Concrete implementations of this class should define a zero-argument42* constructor and implement the abstract methods specified below.43*/44public abstract static class Provider {45/**46* Initializes a new instance of this class.47*/48protected Provider() {}4950/**51* Invoked prior to binding a TCP socket.52*/53public abstract void implBeforeTcpBind(FileDescriptor fdObj,54InetAddress address,55int port)56throws IOException;5758/**59* Invoked prior to connecting an unbound TCP socket.60*/61public abstract void implBeforeTcpConnect(FileDescriptor fdObj,62InetAddress address,63int port)64throws IOException;65}6667/**68* For now, we load the SDP provider on Solaris. In the future this may69* be changed to use the ServiceLoader facility to allow the deployment of70* other providers.71*/72private static final Provider provider = new sun.net.sdp.SdpProvider();7374/**75* Invoke prior to binding a TCP socket.76*/77public static void beforeTcpBind(FileDescriptor fdObj,78InetAddress address,79int port)80throws IOException81{82provider.implBeforeTcpBind(fdObj, address, port);83}8485/**86* Invoke prior to connecting an unbound TCP socket.87*/88public static void beforeTcpConnect(FileDescriptor fdObj,89InetAddress address,90int port)91throws IOException92{93provider.implBeforeTcpConnect(fdObj, address, port);94}95}969798