1 /*
2  * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
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.util.Set;
29 import java.util.HashSet;
30 import sun.net.ext.ExtendedSocketOptions;
31 
32 /*
33  * On Unix systems we simply delegate to native methods.
34  *
35  * @author Chris Hegarty
36  */
37 
38 class PlainSocketImpl extends AbstractPlainSocketImpl
39 {
40     static {
initProto()41         initProto();
42     }
43 
44     /**
45      * Constructs an empty instance.
46      */
PlainSocketImpl(boolean isServer)47     PlainSocketImpl(boolean isServer) {
48         super(isServer);
49     }
50 
socketSetOption(int opt, boolean b, Object val)51     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
52         if (opt == SocketOptions.SO_REUSEPORT &&
53             !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
54             throw new UnsupportedOperationException("unsupported option");
55         }
56         try {
57             socketSetOption0(opt, b, val);
58         } catch (SocketException se) {
59             if (!isConnected)
60                 throw se;
61         }
62     }
63 
socketCreate(boolean stream)64     void socketCreate(boolean stream) throws IOException {
65         socketCreate(stream, isServer);
66     }
67 
socketCreate(boolean stream, boolean isServer)68     native void socketCreate(boolean stream, boolean isServer) throws IOException;
69 
socketConnect(InetAddress address, int port, int timeout)70     native void socketConnect(InetAddress address, int port, int timeout)
71         throws IOException;
72 
socketBind(InetAddress address, int port)73     native void socketBind(InetAddress address, int port)
74         throws IOException;
75 
socketListen(int count)76     native void socketListen(int count) throws IOException;
77 
socketAccept(SocketImpl s)78     native void socketAccept(SocketImpl s) throws IOException;
79 
socketAvailable()80     native int socketAvailable() throws IOException;
81 
socketClose0(boolean useDeferredClose)82     native void socketClose0(boolean useDeferredClose) throws IOException;
83 
socketShutdown(int howto)84     native void socketShutdown(int howto) throws IOException;
85 
initProto()86     static native void initProto();
87 
socketSetOption0(int cmd, boolean on, Object value)88     native void socketSetOption0(int cmd, boolean on, Object value)
89         throws SocketException;
90 
socketGetOption(int opt, Object iaContainerObj)91     native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
92 
socketSendUrgentData(int data)93     native void socketSendUrgentData(int data) throws IOException;
94 }
95