jdk/src/java.base/windows/classes/java/net/PlainSocketImpl.java
author alanb
Tue, 23 Feb 2016 17:41:00 +0000
changeset 36115 0676e37a0b9c
parent 25859 3317bb8137f4
child 37368 bf9b868f1aa8
permissions -rw-r--r--
6432031: Add support for SO_REUSEPORT Reviewed-by: alanb, simonis, chegar Contributed-by: yingqi.lu@intel.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class PlainSocketImpl simply delegates to the appropriate real
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * SocketImpl. We do this because PlainSocketImpl is already extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * by SocksSocketImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * There are two possibilities for the real SocketImpl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * TwoStacksPlainSocketImpl or DualStackPlainSocketImpl. We use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * DualStackPlainSocketImpl on systems that have a dual stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * TCP implementation. Otherwise we create an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * TwoStacksPlainSocketImpl and delegate to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Chris Hegarty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class PlainSocketImpl extends AbstractPlainSocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private AbstractPlainSocketImpl impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /* the windows version. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static float version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /* java.net.preferIPv4Stack */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static boolean preferIPv4Stack = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /* If the version supports a dual stack TCP implementation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static boolean useDualStackImpl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    57
    /* sun.net.useExclusiveBind */
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    58
    private static String exclBindProp;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    59
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    60
    /* True if exclusive binding is on for Windows */
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    61
    private static boolean exclusiveBind = true;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        java.security.AccessController.doPrivileged( new PrivilegedAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                        version = Float.parseFloat(System.getProperties().getProperty("os.version"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                        preferIPv4Stack = Boolean.parseBoolean(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                          System.getProperties().getProperty("java.net.preferIPv4Stack"));
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    71
                        exclBindProp = System.getProperty("sun.net.useExclusiveBind");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    } catch (NumberFormatException e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                        assert false : e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    return null; // nothing to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                } });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // (version >= 6.0) implies Vista or greater.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (version >= 6.0 && !preferIPv4Stack) {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    80
                useDualStackImpl = true;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    81
        }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    82
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    83
        if (exclBindProp != null) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    84
            // sun.net.useExclusiveBind is true
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    85
            exclusiveBind = exclBindProp.length() == 0 ? true
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    86
                    : Boolean.parseBoolean(exclBindProp);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    87
        } else if (version < 6.0) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    88
            exclusiveBind = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Constructs an empty instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    PlainSocketImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (useDualStackImpl) {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    97
            impl = new DualStackPlainSocketImpl(exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } else {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    99
            impl = new TwoStacksPlainSocketImpl(exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Constructs an instance with the given file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    PlainSocketImpl(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (useDualStackImpl) {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
   108
            impl = new DualStackPlainSocketImpl(fd, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
   110
            impl = new TwoStacksPlainSocketImpl(fd, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // Override methods in SocketImpl that access impl's fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected FileDescriptor getFileDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return impl.getFileDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected InetAddress getInetAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return impl.getInetAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return impl.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected int getLocalPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return impl.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    void setSocket(Socket soc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        impl.setSocket(soc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    Socket getSocket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return impl.getSocket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    void setServerSocket(ServerSocket soc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        impl.setServerSocket(soc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    ServerSocket getServerSocket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return impl.getServerSocket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return impl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // Override methods in AbstractPlainSocketImpl that access impl's fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected synchronized void create(boolean stream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        impl.create(stream);
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   156
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   157
        // set fd to delegate's fd to be compatible with older releases
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   158
        this.fd = impl.fd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected void connect(String host, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throws UnknownHostException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        impl.connect(host, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected void connect(InetAddress address, int port) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        impl.connect(address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected void connect(SocketAddress address, int timeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        impl.connect(address, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void setOption(int opt, Object val) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   176
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   177
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   178
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   179
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        impl.setOption(opt, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public Object getOption(int opt) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   184
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   185
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   186
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   187
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return impl.getOption(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        impl.doConnect(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   195
    protected synchronized void bind(InetAddress address, int lport)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        impl.bind(address, lport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected synchronized void accept(SocketImpl s) throws IOException {
20501
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   202
        if (s instanceof PlainSocketImpl) {
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   203
            // pass in the real impl not the wrapper.
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   204
            SocketImpl delegate = ((PlainSocketImpl)s).impl;
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   205
            delegate.address = new InetAddress();
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   206
            delegate.fd = new FileDescriptor();
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   207
            impl.accept(delegate);
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   208
            // set fd to delegate's fd to be compatible with older releases
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   209
            s.fd = delegate.fd;
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   210
        } else {
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   211
            impl.accept(s);
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   212
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    void setFileDescriptor(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        impl.setFileDescriptor(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    void setAddress(InetAddress address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        impl.setAddress(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    void setPort(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        impl.setPort(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    void setLocalPort(int localPort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        impl.setLocalPort(localPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    protected synchronized InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return impl.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    void setInputStream(SocketInputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        impl.setInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    protected synchronized OutputStream getOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return impl.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    protected void close() throws IOException {
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   244
        try {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   245
            impl.close();
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   246
        } finally {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   247
            // set fd to delegate's fd to be compatible with older releases
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   248
            this.fd = null;
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   249
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    void reset() throws IOException {
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   253
        try {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   254
            impl.reset();
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   255
        } finally {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   256
            // set fd to delegate's fd to be compatible with older releases
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   257
            this.fd = null;
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   258
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected void shutdownInput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        impl.shutdownInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    protected void shutdownOutput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        impl.shutdownOutput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    protected void sendUrgentData(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        impl.sendUrgentData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    FileDescriptor acquireFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return impl.acquireFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    void releaseFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        impl.releaseFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public boolean isConnectionReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return impl.isConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public boolean isConnectionResetPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return impl.isConnectionResetPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void setConnectionReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        impl.setConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void setConnectionResetPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        impl.setConnectionResetPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public boolean isClosedOrPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return impl.isClosedOrPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public int getTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return impl.getTimeout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    // Override methods in AbstractPlainSocketImpl that need to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    void socketCreate(boolean isServer) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        impl.socketCreate(isServer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    void socketConnect(InetAddress address, int port, int timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        impl.socketConnect(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    void socketBind(InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        impl.socketBind(address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    void socketListen(int count) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        impl.socketListen(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    void socketAccept(SocketImpl s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        impl.socketAccept(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    int socketAvailable() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return impl.socketAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    void socketClose0(boolean useDeferredClose) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        impl.socketClose0(useDeferredClose);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    void socketShutdown(int howto) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        impl.socketShutdown(howto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    void socketSetOption(int cmd, boolean on, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   343
        if (cmd == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   344
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   345
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   346
        }
11019
aa969c520286 7107020: java.net.PlainSocketImpl.socketSetOption() calls itself
chegar
parents: 9035
diff changeset
   347
        impl.socketSetOption(cmd, on, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    int socketGetOption(int opt, Object iaContainerObj) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   351
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   352
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   353
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   354
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return impl.socketGetOption(opt, iaContainerObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    void socketSendUrgentData(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        impl.socketSendUrgentData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   361
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   362
    static boolean isReusePortAvailable() {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   363
        // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   364
        return false;
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   365
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
}