jdk/src/solaris/classes/sun/nio/ch/SctpServerChannelImpl.java
author jjg
Thu, 28 Jul 2011 13:34:31 -0700
changeset 10137 d92637d3d673
parent 9679 d98ae8bc45fc
permissions -rw-r--r--
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror Reviewed-by: alanb, chegar Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
     2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
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: 4669
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
package sun.nio.ch;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
import java.net.SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
import java.net.InetSocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
import java.net.InetAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
import java.io.FileDescriptor;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
import java.io.IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
import java.util.Collections;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
import java.util.Set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.HashSet;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.nio.channels.SelectionKey;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
import java.nio.channels.ClosedChannelException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import java.nio.channels.NotYetBoundException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import java.nio.channels.spi.SelectorProvider;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
import com.sun.nio.sctp.IllegalUnbindException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
import com.sun.nio.sctp.SctpChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
import com.sun.nio.sctp.SctpServerChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
import com.sun.nio.sctp.SctpSocketOption;
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
    43
import com.sun.nio.sctp.SctpStandardSocketOptions;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
 * An implementation of SctpServerChannel
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
public class SctpServerChannelImpl extends SctpServerChannel
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
    implements SelChImpl
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
{
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
    private final FileDescriptor fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
    private final int fdVal;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
    /* IDs of native thread doing accept, for signalling */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
    private volatile long thread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
    /* Lock held by thread currently blocked in this channel */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
    private final Object lock = new Object();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
    /* Lock held by any thread that modifies the state fields declared below
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
     * DO NOT invoke a blocking I/O operation while holding this lock! */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
    private final Object stateLock = new Object();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
    private enum ChannelState {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
        UNINITIALIZED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
        INUSE,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
        KILLPENDING,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        KILLED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
    /* -- The following fields are protected by stateLock -- */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
    private ChannelState state = ChannelState.UNINITIALIZED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
    /* Binding: Once bound the port will remain constant. */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
    int port = -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
    private HashSet<InetSocketAddress> localAddresses = new HashSet<InetSocketAddress>();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
    /* Has the channel been bound to the wildcard address */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
    private boolean wildcard; /* false */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
    /* -- End of fields protected by stateLock -- */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
     * Initializes a new instance of this class.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    public SctpServerChannelImpl(SelectorProvider provider)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
        //TODO: update provider remove public modifier
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
        super(provider);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
        this.fd = SctpNet.socket(true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
        this.fdVal = IOUtil.fdVal(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
        this.state = ChannelState.INUSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
    public SctpServerChannel bind(SocketAddress local, int backlog)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
        synchronized (lock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
            synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
                if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
                    throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
                if (isBound())
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   102
                    SctpNet.throwAlreadyBoundException();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
                InetSocketAddress isa = (local == null) ?
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
                    new InetSocketAddress(0) : Net.checkAddress(local);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
                SecurityManager sm = System.getSecurityManager();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
                if (sm != null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
                    sm.checkListen(isa.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
                Net.bind(fd, isa.getAddress(), isa.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
                InetSocketAddress boundIsa = Net.localAddress(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
                port = boundIsa.getPort();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
                localAddresses.add(isa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
                    if (isa.getAddress().isAnyLocalAddress())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
                        wildcard = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   117
                SctpNet.listen(fdVal, backlog < 1 ? 50 : backlog);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
    public SctpServerChannel bindAddress(InetAddress address)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
        return bindUnbindAddress(address, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
    public SctpServerChannel unbindAddress(InetAddress address)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
        return bindUnbindAddress(address, false);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
    private SctpServerChannel bindUnbindAddress(InetAddress address, boolean add)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
        if (address == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
            throw new IllegalArgumentException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
        synchronized (lock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
            synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
                if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
                    throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
                if (!isBound())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
                    throw new NotYetBoundException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
                if (wildcard)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
                    throw new IllegalStateException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
                            "Cannot add or remove addresses from a channel that is bound to the wildcard address");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
                if (address.isAnyLocalAddress())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
                    throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
                            "Cannot add or remove the wildcard address");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
                if (add) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
                    for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
                        if (addr.getAddress().equals(address)) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   155
                            SctpNet.throwAlreadyBoundException();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
                } else { /*removing */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
                    /* Verify that there is more than one address
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
                     * and that address is already bound */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
                    if (localAddresses.size() <= 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
                        throw new IllegalUnbindException("Cannot remove address from a channel with only one address bound");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
                    boolean foundAddress = false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
                    for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
                        if (addr.getAddress().equals(address)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
                            foundAddress = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
                            break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
                    if (!foundAddress )
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
                        throw new IllegalUnbindException("Cannot remove address from a channel that is not bound to that address");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   172
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   173
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
                SctpNet.bindx(fdVal, new InetAddress[]{address}, port, add);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
                /* Update our internal Set to reflect the addition/removal */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
                if (add)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
                    localAddresses.add(new InetSocketAddress(address, port));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
                else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
                    for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
                        if (addr.getAddress().equals(address)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
                            localAddresses.remove(addr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
                            break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
    private boolean isBound() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
            return port == -1 ? false : true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   196
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   197
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   198
    private void acceptCleanup() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
            thread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
            if (state == ChannelState.KILLPENDING)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
    public SctpChannel accept() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
        synchronized (lock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
            if (!isBound())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
                throw new NotYetBoundException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
            SctpChannel sc = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
            int n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
            FileDescriptor newfd = new FileDescriptor();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
            InetSocketAddress[] isaa = new InetSocketAddress[1];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
                begin();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
                if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
                    return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
                thread = NativeThread.current();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
                for (;;) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
                    n = accept0(fd, newfd, isaa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
                    if ((n == IOStatus.INTERRUPTED) && isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
                        continue;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
                    break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
            } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
                acceptCleanup();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
                end(n > 0);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
                assert IOStatus.check(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
            if (n < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
                return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
            IOUtil.configureBlocking(newfd, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
            InetSocketAddress isa = isaa[0];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
            sc = new SctpChannelImpl(provider(), newfd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
            SecurityManager sm = System.getSecurityManager();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
            if (sm != null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
                sm.checkAccept(isa.getAddress().getHostAddress(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
                               isa.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   247
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   248
            return sc;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   249
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   250
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   251
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   252
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   253
    protected void implConfigureBlocking(boolean block) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   254
        IOUtil.configureBlocking(fd, block);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   255
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   256
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   257
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   258
    public void implCloseSelectableChannel() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   259
        synchronized (stateLock) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   260
            SctpNet.preClose(fdVal);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   261
            if (thread != 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   262
                NativeThread.signal(thread);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   263
            if (!isRegistered())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   264
                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   265
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   266
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   267
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   268
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   269
    public void kill() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   270
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   271
            if (state == ChannelState.KILLED)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   272
                return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   273
            if (state == ChannelState.UNINITIALIZED) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   274
                state = ChannelState.KILLED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   275
                return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   276
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   277
            assert !isOpen() && !isRegistered();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   278
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   279
            // Postpone the kill if there is a thread in accept
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   280
            if (thread == 0) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   281
                SctpNet.close(fdVal);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   282
                state = ChannelState.KILLED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   283
            } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   284
                state = ChannelState.KILLPENDING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   285
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   286
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   287
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   288
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   289
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   290
    public FileDescriptor getFD() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   291
        return fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   292
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   293
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   294
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   295
    public int getFDVal() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   296
        return fdVal;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   297
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   298
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   299
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   300
     * Translates native poll revent ops into a ready operation ops
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   301
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   302
    private boolean translateReadyOps(int ops, int initialOps,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   303
                                     SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   304
        int intOps = sk.nioInterestOps();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   305
        int oldOps = sk.nioReadyOps();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   306
        int newOps = initialOps;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   307
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   308
        if ((ops & PollArrayWrapper.POLLNVAL) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   309
            /* This should only happen if this channel is pre-closed while a
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   310
             * selection operation is in progress
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   311
             * ## Throw an error if this channel has not been pre-closed */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   312
            return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   313
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   314
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   315
        if ((ops & (PollArrayWrapper.POLLERR
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   316
                    | PollArrayWrapper.POLLHUP)) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   317
            newOps = intOps;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   318
            sk.nioReadyOps(newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   319
            return (newOps & ~oldOps) != 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   320
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   321
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   322
        if (((ops & PollArrayWrapper.POLLIN) != 0) &&
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   323
            ((intOps & SelectionKey.OP_ACCEPT) != 0))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   324
                newOps |= SelectionKey.OP_ACCEPT;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   325
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   326
        sk.nioReadyOps(newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   327
        return (newOps & ~oldOps) != 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   328
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   329
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   330
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   331
    public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   332
        return translateReadyOps(ops, sk.nioReadyOps(), sk);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   333
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   334
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   335
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   336
    public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   337
        return translateReadyOps(ops, 0, sk);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   338
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   339
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   340
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   341
    public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   342
        int newOps = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   343
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   344
        /* Translate ops */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   345
        if ((ops & SelectionKey.OP_ACCEPT) != 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   346
            newOps |= PollArrayWrapper.POLLIN;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   347
        /* Place ops into pollfd array */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   348
        sk.selector.putEventOps(sk, newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   349
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   350
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   351
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   352
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   353
    public <T> SctpServerChannel setOption(SctpSocketOption<T> name, T value)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   354
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   355
        if (name == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   356
            throw new NullPointerException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   357
        if (!supportedOptions().contains(name))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   358
            throw new UnsupportedOperationException("'" + name + "' not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   359
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   360
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   361
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   362
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   363
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   364
            SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   365
            return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   366
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   367
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   368
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   369
    @Override
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   370
    @SuppressWarnings("unchecked")
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   371
    public <T> T getOption(SctpSocketOption<T> name) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   372
        if (name == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   373
            throw new NullPointerException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   374
        if (!supportedOptions().contains(name))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   375
            throw new UnsupportedOperationException("'" + name + "' not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   376
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   377
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   378
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   379
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   380
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   381
            return (T) SctpNet.getSocketOption(fdVal, name, 0 /*oneToOne*/);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   382
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   383
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   384
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   385
    private static class DefaultOptionsHolder {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   386
        static final Set<SctpSocketOption<?>> defaultOptions = defaultOptions();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   387
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   388
        private static Set<SctpSocketOption<?>> defaultOptions() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   389
            HashSet<SctpSocketOption<?>> set = new HashSet<SctpSocketOption<?>>(1);
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   390
            set.add(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   391
            return Collections.unmodifiableSet(set);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   392
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   393
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   394
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   395
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   396
    public final Set<SctpSocketOption<?>> supportedOptions() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   397
        return DefaultOptionsHolder.defaultOptions;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   398
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   399
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   400
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   401
    public Set<SocketAddress> getAllLocalAddresses()
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   402
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   403
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   404
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   405
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   406
            if (!isBound())
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   407
                return Collections.emptySet();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   408
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   409
            return SctpNet.getLocalAddresses(fdVal);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   410
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   411
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   412
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   413
    /* Native */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   414
    private static native void initIDs();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   415
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   416
    private static native int accept0(FileDescriptor ssfd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   417
        FileDescriptor newfd, InetSocketAddress[] isaa) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   418
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   419
    static {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   420
        Util.load();   // loads nio & net native libraries
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   421
        java.security.AccessController.doPrivileged(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   422
                new sun.security.action.LoadLibraryAction("sctp"));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   423
        initIDs();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   424
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   425
}