src/java.base/windows/classes/java/net/PlainSocketImpl.java
author alanb
Thu, 15 Mar 2018 11:02:22 +0000
changeset 49249 92cca24c8807
parent 47216 71c04702a3d5
child 49833 06a6ae39d892
permissions -rw-r--r--
8199329: Remove code that attempts to read bytes after connection reset reported Reviewed-by: redestad, clanger, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49249
92cca24c8807 8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, 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.*;
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    28
import java.security.AccessController;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.PrivilegedAction;
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    30
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class PlainSocketImpl simply delegates to the appropriate real
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * SocketImpl. We do this because PlainSocketImpl is already extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * by SocksSocketImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * There are two possibilities for the real SocketImpl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * TwoStacksPlainSocketImpl or DualStackPlainSocketImpl. We use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * DualStackPlainSocketImpl on systems that have a dual stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * TCP implementation. Otherwise we create an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * TwoStacksPlainSocketImpl and delegate to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Chris Hegarty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
49249
92cca24c8807 8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents: 47216
diff changeset
    46
class PlainSocketImpl extends AbstractPlainSocketImpl {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private AbstractPlainSocketImpl impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /* java.net.preferIPv4Stack */
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    50
    private static final boolean preferIPv4Stack;
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    51
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    52
    /* True if exclusive binding is on for Windows */
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    53
    private static final boolean exclusiveBind;
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    54
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static {
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    56
        preferIPv4Stack = Boolean.parseBoolean(
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    57
        AccessController.doPrivileged(
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    58
                new GetPropertyAction("java.net.preferIPv4Stack")));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    60
        String exclBindProp = AccessController.doPrivileged(
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    61
                new GetPropertyAction("sun.net.useExclusiveBind", ""));
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    62
        exclusiveBind = (exclBindProp.isEmpty())
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    63
                ? true
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    64
                : Boolean.parseBoolean(exclBindProp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Constructs an empty instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    PlainSocketImpl() {
37368
bf9b868f1aa8 8154238: Drop code to support Windows XP in windows socket impl
redestad
parents: 36115
diff changeset
    71
        if (!preferIPv4Stack) {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    72
            impl = new DualStackPlainSocketImpl(exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } else {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    74
            impl = new TwoStacksPlainSocketImpl(exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructs an instance with the given file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    PlainSocketImpl(FileDescriptor fd) {
37370
4dcebdd2bbc0 8154454: Fix compilation issue in PlainSocketImpl
redestad
parents: 37368
diff changeset
    82
        if (!preferIPv4Stack) {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    83
            impl = new DualStackPlainSocketImpl(fd, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } else {
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 11019
diff changeset
    85
            impl = new TwoStacksPlainSocketImpl(fd, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Override methods in SocketImpl that access impl's fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected FileDescriptor getFileDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return impl.getFileDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected InetAddress getInetAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return impl.getInetAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return impl.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected int getLocalPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return impl.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void setSocket(Socket soc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        impl.setSocket(soc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    Socket getSocket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return impl.getSocket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    void setServerSocket(ServerSocket soc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        impl.setServerSocket(soc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    ServerSocket getServerSocket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return impl.getServerSocket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return impl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // Override methods in AbstractPlainSocketImpl that access impl's fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected synchronized void create(boolean stream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        impl.create(stream);
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   131
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   132
        // 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
   133
        this.fd = impl.fd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected void connect(String host, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        throws UnknownHostException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        impl.connect(host, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected void connect(InetAddress address, int port) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        impl.connect(address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected void connect(SocketAddress address, int timeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        impl.connect(address, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void setOption(int opt, Object val) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   151
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   152
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   153
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   154
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        impl.setOption(opt, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public Object getOption(int opt) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   159
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   160
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   161
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   162
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return impl.getOption(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        impl.doConnect(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   170
    protected synchronized void bind(InetAddress address, int lport)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        impl.bind(address, lport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    protected synchronized void accept(SocketImpl s) throws IOException {
20501
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   177
        if (s instanceof PlainSocketImpl) {
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   178
            // pass in the real impl not the wrapper.
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   179
            SocketImpl delegate = ((PlainSocketImpl)s).impl;
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   180
            delegate.address = new InetAddress();
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   181
            delegate.fd = new FileDescriptor();
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   182
            impl.accept(delegate);
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   183
            // 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
   184
            s.fd = delegate.fd;
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   185
        } else {
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   186
            impl.accept(s);
058de8b0a499 8024952: ClassCastException in PlainSocketImpl.accept() when using custom socketImpl
coffeys
parents: 18192
diff changeset
   187
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    void setFileDescriptor(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        impl.setFileDescriptor(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    void setAddress(InetAddress address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        impl.setAddress(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    void setPort(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        impl.setPort(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    void setLocalPort(int localPort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        impl.setLocalPort(localPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    protected synchronized InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return impl.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    void setInputStream(SocketInputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        impl.setInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    protected synchronized OutputStream getOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return impl.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    protected void close() throws IOException {
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   219
        try {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   220
            impl.close();
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   221
        } finally {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   222
            // 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
   223
            this.fd = null;
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   224
        }
2
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 reset() throws IOException {
8185
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   228
        try {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   229
            impl.reset();
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   230
        } finally {
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   231
            // 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
   232
            this.fd = null;
6bf10e071117 7016898: PlainSocketImpl.fd is null on Windows
chegar
parents: 5506
diff changeset
   233
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    protected void shutdownInput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        impl.shutdownInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    protected void shutdownOutput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        impl.shutdownOutput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void sendUrgentData(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        impl.sendUrgentData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    FileDescriptor acquireFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return impl.acquireFD();
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 releaseFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        impl.releaseFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
49249
92cca24c8807 8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents: 47216
diff changeset
   256
    boolean isConnectionReset() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return impl.isConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
49249
92cca24c8807 8199329: Remove code that attempts to read bytes after connection reset reported
alanb
parents: 47216
diff changeset
   260
    void setConnectionReset() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        impl.setConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public boolean isClosedOrPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return impl.isClosedOrPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public int getTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return impl.getTimeout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    // Override methods in AbstractPlainSocketImpl that need to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    void socketCreate(boolean isServer) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        impl.socketCreate(isServer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    void socketConnect(InetAddress address, int port, int timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        impl.socketConnect(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    void socketBind(InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        impl.socketBind(address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    void socketListen(int count) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        impl.socketListen(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    void socketAccept(SocketImpl s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        impl.socketAccept(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    int socketAvailable() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return impl.socketAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    void socketClose0(boolean useDeferredClose) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        impl.socketClose0(useDeferredClose);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    void socketShutdown(int howto) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        impl.socketShutdown(howto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    void socketSetOption(int cmd, boolean on, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   310
        if (cmd == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   311
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   312
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   313
        }
11019
aa969c520286 7107020: java.net.PlainSocketImpl.socketSetOption() calls itself
chegar
parents: 9035
diff changeset
   314
        impl.socketSetOption(cmd, on, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    int socketGetOption(int opt, Object iaContainerObj) throws SocketException {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   318
        if (opt == SocketOptions.SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   319
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   320
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   321
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return impl.socketGetOption(opt, iaContainerObj);
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 socketSendUrgentData(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        impl.socketSendUrgentData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   328
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   329
    static boolean isReusePortAvailable() {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   330
        // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   331
        return false;
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   332
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}