jdk/src/java.base/windows/classes/java/net/TwoStacksPlainSocketImpl.java
author alanb
Tue, 23 Feb 2016 17:41:00 +0000
changeset 36115 0676e37a0b9c
parent 25859 3317bb8137f4
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.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.FileDescriptor;
10708
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
    29
import sun.net.ResourceManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class defines the plain SocketImpl that is used for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Windows version lower than Vista. It adds support for IPv6 on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * these platforms where available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * For backward compatibility Windows platforms that do not have IPv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * support also use this implementation, and fd1 gets set to null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * during socket creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Chris Hegarty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /* second fd, used for ipv6 on windows only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * fd1 is used for listeners and for client sockets at initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * until the socket is connected. Up to this point fd always refers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * to the ipv4 socket and fd1 to the ipv6 socket. After the socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * becomes connected, fd always refers to the connected socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * (either v4 or v6) and fd1 is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * For ServerSockets, fd always refers to the v4 listener and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * fd1 the v6 listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private FileDescriptor fd1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Needed for ipv6 on windows because we need to know
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * if the socket is bound to ::0 or 0.0.0.0, when a caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * asks for it. Otherwise we don't know which socket to ask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private InetAddress anyLocalBoundAddr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* to prevent starvation when listening on two sockets, this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * is used to hold the id of the last socket we accepted on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int lastfd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    69
    // true if this socket is exclusively bound
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    70
    private final boolean exclusiveBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    71
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    72
    // emulates SO_REUSEADDR when exclusiveBind is true
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    73
    private boolean isReuseAddress;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    74
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        initProto();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    79
    public TwoStacksPlainSocketImpl(boolean exclBind) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    80
        exclusiveBind = exclBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    81
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    83
    public TwoStacksPlainSocketImpl(FileDescriptor fd, boolean exclBind) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.fd = fd;
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
    85
        exclusiveBind = exclBind;
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
     * Creates a socket with a boolean that specifies whether this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * is a stream socket (true) or an unconnected UDP socket (false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected synchronized void create(boolean stream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        fd1 = new FileDescriptor();
10704
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 5506
diff changeset
    94
        try {
10708
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
    95
            super.create(stream);
10704
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 5506
diff changeset
    96
        } catch (IOException e) {
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 5506
diff changeset
    97
            fd1 = null;
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 5506
diff changeset
    98
            throw e;
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 5506
diff changeset
    99
        }
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
     * Binds the socket to the specified address of the specified local port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param address the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param port the port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected synchronized void bind(InetAddress address, int lport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super.bind(address, lport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (address.isAnyLocalAddress()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            anyLocalBoundAddr = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public Object getOption(int opt) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new SocketException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (opt == SO_BINDADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (fd != null && fd1 != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                /* must be unbound or else bound to anyLocal */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                return anyLocalBoundAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            InetAddressContainer in = new InetAddressContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            socketGetOption(opt, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return in.addr;
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   128
        } else if (opt == SO_REUSEADDR && exclusiveBind) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   129
            // SO_REUSEADDR emulated when using exclusive bind
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   130
            return isReuseAddress;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   131
        } else if (opt == SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   132
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   133
            throw new UnsupportedOperationException("unsupported option");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return super.getOption(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   138
    @Override
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   139
    void socketBind(InetAddress address, int port) throws IOException {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   140
        socketBind(address, port, exclusiveBind);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   141
    }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   142
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   143
    @Override
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   144
    void socketSetOption(int opt, boolean on, Object value)
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   145
        throws SocketException
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   146
    {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   147
        // SO_REUSEADDR emulated when using exclusive bind
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   148
        if (opt == SO_REUSEADDR && exclusiveBind)
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   149
            isReuseAddress = on;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   150
        else if (opt == SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   151
            // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   152
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   153
        }
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   154
        else
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   155
            socketNativeSetOption(opt, on, value);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   156
    }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   157
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Closes the socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   161
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        synchronized(fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (fd != null || fd1 != null) {
10708
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
   165
                if (!stream) {
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
   166
                    ResourceManager.afterUdpClose();
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
   167
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (fdUseCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    if (closePending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    closePending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    fd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    fd1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                     * If a thread has acquired the fd and a close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                     * isn't pending then use a deferred close.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                     * Also decrement fdUseCount to signal the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                     * thread that releases the fd to close it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    if (!closePending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        closePending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        fdUseCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   194
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    void reset() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (fd != null || fd1 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        fd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        fd1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Return true if already closed or close is pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   207
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public boolean isClosedOrPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * Lock on fdLock to ensure that we wait if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * close is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        synchronized (fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (closePending || (fd == null && fd1 == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /* Native methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    static native void initProto();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    native void socketCreate(boolean isServer) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    native void socketConnect(InetAddress address, int port, int timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   231
    native void socketBind(InetAddress address, int port, boolean exclBind)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    native void socketListen(int count) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    native void socketAccept(SocketImpl s) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    native int socketAvailable() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    native void socketClose0(boolean useDeferredClose) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    native void socketShutdown(int howto) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   244
    native void socketNativeSetOption(int cmd, boolean on, Object value)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    native void socketSendUrgentData(int data) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}