jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
author michaelm
Wed, 25 Jun 2014 15:55:42 +0100
changeset 25170 f58832169add
parent 24969 afa6934dd8e8
permissions -rw-r--r--
8029607: Type of Service (TOS) cannot be set in IPv6 header Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 22604
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 2446
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: 2446
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: 2446
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2446
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2446
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.spi.*;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    33
import java.util.*;
2446
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 2057
diff changeset
    34
import sun.net.NetHooks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * An implementation of ServerSocketChannels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class ServerSocketChannelImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    extends ServerSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    implements SelChImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // Used to make native close and configure calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static NativeDispatcher nd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // Our file descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final FileDescriptor fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // fd value needed for dev/poll. This value will remain valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // even after the value in the file descriptor object has been set to -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int fdVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // ID of native thread currently blocked in this channel, for signalling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private volatile long thread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // Lock held by thread currently blocked in this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // Lock held by any thread that modifies the state fields declared below
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // DO NOT invoke a blocking I/O operation while holding this lock!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final Object stateLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // -- The following fields are protected by stateLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // Channel state, increases monotonically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final int ST_UNINITIALIZED = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int ST_INUSE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int ST_KILLED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private int state = ST_UNINITIALIZED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // Binding
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
    75
    private InetSocketAddress localAddress; // null => unbound
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
    77
    // set true when exclusive binding is on and SO_REUSEADDR is emulated
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
    78
    private boolean isReuseAddress;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
    79
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // Our socket adaptor, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ServerSocket socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // -- End of fields protected by stateLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
6525
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
    86
    ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        super(sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.fd =  Net.serverSocket(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.fdVal = IOUtil.fdVal(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.state = ST_INUSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
6525
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
    93
    ServerSocketChannelImpl(SelectorProvider sp,
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
    94
                            FileDescriptor fd,
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
    95
                            boolean bound)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super(sp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.fd =  fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.fdVal = IOUtil.fdVal(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.state = ST_INUSE;
6525
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
   102
        if (bound)
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents: 5506
diff changeset
   103
            localAddress = Net.localAddress(fd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public ServerSocket socket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        synchronized (stateLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (socket == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                socket = ServerSocketAdaptor.create(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   114
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   115
    public SocketAddress getLocalAddress() throws IOException {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   116
        synchronized (stateLock) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   117
            if (!isOpen())
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   118
                throw new ClosedChannelException();
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   119
            return localAddress == null ? localAddress
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   120
                    : Net.getRevealedLocalAddress(
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   121
                          Net.asInetSocketAddress(localAddress));
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   122
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   123
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   124
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   125
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   126
    public <T> ServerSocketChannel setOption(SocketOption<T> name, T value)
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   127
        throws IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   128
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   129
        if (name == null)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   130
            throw new NullPointerException();
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   131
        if (!supportedOptions().contains(name))
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   132
            throw new UnsupportedOperationException("'" + name + "' not supported");
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   133
        synchronized (stateLock) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   134
            if (!isOpen())
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   135
                throw new ClosedChannelException();
25170
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   136
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   137
            if (name == StandardSocketOptions.IP_TOS) {
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   138
                ProtocolFamily family = Net.isIPv6Available() ?
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   139
                    StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   140
                Net.setSocketOption(fd, family, name, value);
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   141
                return this;
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   142
            }
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   143
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   144
            if (name == StandardSocketOptions.SO_REUSEADDR &&
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   145
                    Net.useExclusiveBind())
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   146
            {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   147
                // SO_REUSEADDR emulated when using exclusive bind
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   148
                isReuseAddress = (Boolean)value;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   149
            } else {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   150
                // no options that require special handling
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   151
                Net.setSocketOption(fd, Net.UNSPEC, name, value);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   152
            }
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   153
            return this;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   154
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   155
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   156
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   157
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   158
    @SuppressWarnings("unchecked")
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   159
    public <T> T getOption(SocketOption<T> name)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   160
        throws IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   161
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   162
        if (name == null)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   163
            throw new NullPointerException();
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   164
        if (!supportedOptions().contains(name))
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   165
            throw new UnsupportedOperationException("'" + name + "' not supported");
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   166
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   167
        synchronized (stateLock) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   168
            if (!isOpen())
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   169
                throw new ClosedChannelException();
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   170
            if (name == StandardSocketOptions.SO_REUSEADDR &&
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   171
                    Net.useExclusiveBind())
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   172
            {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   173
                // SO_REUSEADDR emulated when using exclusive bind
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   174
                return (T)Boolean.valueOf(isReuseAddress);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14025
diff changeset
   175
            }
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   176
            // no options that require special handling
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   177
            return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   178
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   179
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   180
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   181
    private static class DefaultOptionsHolder {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   182
        static final Set<SocketOption<?>> defaultOptions = defaultOptions();
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   183
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   184
        private static Set<SocketOption<?>> defaultOptions() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   185
            HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(2);
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   186
            set.add(StandardSocketOptions.SO_RCVBUF);
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   187
            set.add(StandardSocketOptions.SO_REUSEADDR);
25170
f58832169add 8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents: 24969
diff changeset
   188
            set.add(StandardSocketOptions.IP_TOS);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   189
            return Collections.unmodifiableSet(set);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   190
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   191
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   192
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   193
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   194
    public final Set<SocketOption<?>> supportedOptions() {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   195
        return DefaultOptionsHolder.defaultOptions;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   196
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   197
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public boolean isBound() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        synchronized (stateLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return localAddress != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   204
    public InetSocketAddress localAddress() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        synchronized (stateLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return localAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   210
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   211
    public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (!isOpen())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new ClosedChannelException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (isBound())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                throw new AlreadyBoundException();
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   217
            InetSocketAddress isa = (local == null) ? new InetSocketAddress(0) :
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   218
                Net.checkAddress(local);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                sm.checkListen(isa.getPort());
2446
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 2057
diff changeset
   222
            NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            Net.bind(fd, isa.getAddress(), isa.getPort());
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   224
            Net.listen(fd, backlog < 1 ? 50 : backlog);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            synchronized (stateLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                localAddress = Net.localAddress(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   229
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public SocketChannel accept() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (!isOpen())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                throw new ClosedChannelException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (!isBound())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                throw new NotYetBoundException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            SocketChannel sc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            FileDescriptor newfd = new FileDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            InetSocketAddress[] isaa = new InetSocketAddress[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                begin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (!isOpen())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                thread = NativeThread.current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    n = accept0(this.fd, newfd, isaa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    if ((n == IOStatus.INTERRUPTED) && isOpen())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                thread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                end(n > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                assert IOStatus.check(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (n < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            IOUtil.configureBlocking(newfd, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            InetSocketAddress isa = isaa[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            sc = new SocketChannelImpl(provider(), newfd, isa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    sm.checkAccept(isa.getAddress().getHostAddress(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                   isa.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                } catch (SecurityException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    sc.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return sc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected void implConfigureBlocking(boolean block) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        IOUtil.configureBlocking(fd, block);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    protected void implCloseSelectableChannel() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        synchronized (stateLock) {
12440
2689ca179e22 7118373: (se) Potential leak file descriptor when deregistrating at around the same time as an async close
robm
parents: 9679
diff changeset
   288
            if (state != ST_KILLED)
2689ca179e22 7118373: (se) Potential leak file descriptor when deregistrating at around the same time as an async close
robm
parents: 9679
diff changeset
   289
                nd.preClose(fd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            long th = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (th != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                NativeThread.signal(th);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if (!isRegistered())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                kill();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void kill() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        synchronized (stateLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (state == ST_KILLED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (state == ST_UNINITIALIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                state = ST_KILLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            assert !isOpen() && !isRegistered();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            nd.close(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            state = ST_KILLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Translates native poll revent set into a ready operation set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public boolean translateReadyOps(int ops, int initialOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                     SelectionKeyImpl sk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int oldOps = sk.nioReadyOps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int newOps = initialOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   321
        if ((ops & Net.POLLNVAL) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            // This should only happen if this channel is pre-closed while a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            // selection operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // ## Throw an error if this channel has not been pre-closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   328
        if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            newOps = intOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            sk.nioReadyOps(newOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            return (newOps & ~oldOps) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   334
        if (((ops & Net.POLLIN) != 0) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            ((intOps & SelectionKey.OP_ACCEPT) != 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                newOps |= SelectionKey.OP_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        sk.nioReadyOps(newOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return (newOps & ~oldOps) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return translateReadyOps(ops, sk.nioReadyOps(), sk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return translateReadyOps(ops, 0, sk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
14025
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   350
    // package-private
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   351
    int poll(int events, long timeout) throws IOException {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   352
        assert Thread.holdsLock(blockingLock()) && !isBlocking();
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   353
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   354
        synchronized (lock) {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   355
            int n = 0;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   356
            try {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   357
                begin();
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   358
                synchronized (stateLock) {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   359
                    if (!isOpen())
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   360
                        return 0;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   361
                    thread = NativeThread.current();
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   362
                }
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   363
                n = Net.poll(fd, events, timeout);
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   364
            } finally {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   365
                thread = 0;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   366
                end(n > 0);
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   367
            }
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   368
            return n;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   369
        }
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   370
    }
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 12440
diff changeset
   371
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Translates an interest operation set into a native poll event set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        int newOps = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // Translate ops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if ((ops & SelectionKey.OP_ACCEPT) != 0)
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   380
            newOps |= Net.POLLIN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        // Place ops into pollfd array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        sk.selector.putEventOps(sk, newOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public FileDescriptor getFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public int getFDVal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return fdVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   394
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        sb.append(this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        sb.append('[');
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   397
        if (!isOpen()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            sb.append("closed");
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   399
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            synchronized (stateLock) {
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   401
                InetSocketAddress addr = localAddress();
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   402
                if (addr == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    sb.append("unbound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                } else {
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 18192
diff changeset
   405
                    sb.append(Net.getRevealedLocalAddressAsString(addr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        sb.append(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    // -- Native methods --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    // Accepts a new connection, setting the given file descriptor to refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    // the new socket and setting isaa[0] to the socket's remote address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    // Returns 1 on success, or IOStatus.UNAVAILABLE (if non-blocking and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // connections are pending) or IOStatus.INTERRUPTED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    private native int accept0(FileDescriptor ssfd, FileDescriptor newfd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                               InetSocketAddress[] isaa)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    static {
19607
bee007586d06 8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents: 18212
diff changeset
   427
        IOUtil.load();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        nd = new SocketDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
}