src/solaris/classes/java/net/PlainSocketImpl.java

Print this page
rev 9687 : * * *


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.net;
  26 
  27 import java.io.IOException;
  28 import java.io.FileDescriptor;




  29 


  30 /*
  31  * On Unix systems we simply delegate to native methods.
  32  *
  33  * @author Chris Hegarty
  34  */
  35 
  36 class PlainSocketImpl extends AbstractPlainSocketImpl
  37 {
  38     static {
  39         initProto();
  40     }
  41 
  42     /**
  43      * Constructs an empty instance.
  44      */
  45     PlainSocketImpl() { }
  46 
  47     /**
  48      * Constructs an instance with the given file descriptor.
  49      */
  50     PlainSocketImpl(FileDescriptor fd) {
  51         this.fd = fd;
  52     }
  53 








































  54     native void socketCreate(boolean isServer) throws IOException;
  55 
  56     native void socketConnect(InetAddress address, int port, int timeout)
  57         throws IOException;
  58 
  59     native void socketBind(InetAddress address, int port)
  60         throws IOException;
  61 
  62     native void socketListen(int count) throws IOException;
  63 
  64     native void socketAccept(SocketImpl s) throws IOException;
  65 
  66     native int socketAvailable() throws IOException;
  67 
  68     native void socketClose0(boolean useDeferredClose) throws IOException;
  69 
  70     native void socketShutdown(int howto) throws IOException;
  71 
  72     static native void initProto();
  73 
  74     native void socketSetOption(int cmd, boolean on, Object value)
  75         throws SocketException;
  76 
  77     native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
  78 
  79     native void socketSendUrgentData(int data) throws IOException;
  80 
  81 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.net;
  26 
  27 import java.io.IOException;
  28 import java.io.FileDescriptor;
  29 import java.util.Set;
  30 import java.util.HashSet;
  31 import java.util.Collections;
  32 import jdk.net.*;
  33 
  34 import static sun.net.ExtendedOptionsImpl.*;
  35 
  36 /*
  37  * On Unix systems we simply delegate to native methods.
  38  *
  39  * @author Chris Hegarty
  40  */
  41 
  42 class PlainSocketImpl extends AbstractPlainSocketImpl
  43 {
  44     static {
  45         initProto();
  46     }
  47 
  48     /**
  49      * Constructs an empty instance.
  50      */
  51     PlainSocketImpl() { }
  52 
  53     /**
  54      * Constructs an instance with the given file descriptor.
  55      */
  56     PlainSocketImpl(FileDescriptor fd) {
  57         this.fd = fd;
  58     }
  59 
  60     protected <T> void setOption(SocketOption<T> name, T value)
  61         throws IOException
  62     {
  63         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
  64             super.setOption(name, value);
  65         } else {
  66             if (isClosedOrPending()) {
  67                 throw new SocketException("Socket closed");
  68             }
  69             setSecurityCheck(name);
  70             checkValueType(value, SocketFlow.class);
  71             setFlowOption(getFileDescriptor(), (SocketFlow)value);
  72         }
  73     }
  74 
  75     protected <T> T getOption(SocketOption<T> name) throws IOException
  76     {
  77         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
  78             return super.getOption(name);
  79         }
  80         if (isClosedOrPending()) {
  81             throw new SocketException("Socket closed");
  82         }
  83         getSecurityCheck(name);
  84         SocketFlow flow = SocketFlow.create();
  85         getFlowOption(getFileDescriptor(), flow);
  86         return (T)flow;
  87     }
  88 
  89     protected Set<SocketOption<?>> supportedOptions()
  90     {
  91         HashSet<SocketOption<?>> options = new HashSet(
  92             super.supportedOptions());
  93 
  94         if (getSocket() != null && flowSupported()) {
  95             options.add(ExtendedSocketOptions.SO_FLOW_SLA);
  96         }
  97         return options;
  98     }
  99 
 100     native void socketCreate(boolean isServer) throws IOException;
 101 
 102     native void socketConnect(InetAddress address, int port, int timeout)
 103         throws IOException;
 104 
 105     native void socketBind(InetAddress address, int port)
 106         throws IOException;
 107 
 108     native void socketListen(int count) throws IOException;
 109 
 110     native void socketAccept(SocketImpl s) throws IOException;
 111 
 112     native int socketAvailable() throws IOException;
 113 
 114     native void socketClose0(boolean useDeferredClose) throws IOException;
 115 
 116     native void socketShutdown(int howto) throws IOException;
 117 
 118     static native void initProto();
 119 
 120     native void socketSetOption(int cmd, boolean on, Object value)
 121         throws SocketException;
 122 
 123     native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
 124 
 125     native void socketSendUrgentData(int data) throws IOException;

 126 }