jdk/src/solaris/classes/sun/nio/ch/sctp/SctpChannelImpl.java
author simonis
Mon, 20 Jan 2014 09:24:25 +0100
changeset 22604 9b394795e216
parent 19607 bee007586d06
child 22607 ba232b417248
permissions -rw-r--r--
8031997: PPC64: Make the various POLL constants system dependant Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12559
diff changeset
     2
 * Copyright (c) 2009, 2012, 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: 4677
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: 4677
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: 4677
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4677
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4677
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    25
package sun.nio.ch.sctp;
2542
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.InetAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
import java.net.SocketAddress;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    29
import java.net.SocketException;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
import java.net.InetSocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
import java.io.FileDescriptor;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
import java.io.IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
import java.util.Collections;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.Set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.util.HashSet;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
import java.nio.ByteBuffer;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import java.nio.channels.SelectionKey;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import java.nio.channels.ClosedChannelException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
import java.nio.channels.ConnectionPendingException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
import java.nio.channels.NoConnectionPendingException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
import java.nio.channels.AlreadyConnectedException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
import java.nio.channels.NotYetBoundException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
import java.nio.channels.NotYetConnectedException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
import java.nio.channels.spi.SelectorProvider;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
import com.sun.nio.sctp.AbstractNotificationHandler;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
import com.sun.nio.sctp.Association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
import com.sun.nio.sctp.AssociationChangeNotification;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
import com.sun.nio.sctp.HandlerResult;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
import com.sun.nio.sctp.IllegalReceiveException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
import com.sun.nio.sctp.InvalidStreamException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
import com.sun.nio.sctp.IllegalUnbindException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
import com.sun.nio.sctp.MessageInfo;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
import com.sun.nio.sctp.NotificationHandler;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
import com.sun.nio.sctp.SctpChannel;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
import com.sun.nio.sctp.SctpSocketOption;
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    56
import sun.nio.ch.DirectBuffer;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    57
import sun.nio.ch.IOStatus;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    58
import sun.nio.ch.IOUtil;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    59
import sun.nio.ch.NativeThread;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    60
import sun.nio.ch.Net;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    61
import sun.nio.ch.PollArrayWrapper;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    62
import sun.nio.ch.SelChImpl;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    63
import sun.nio.ch.SelectionKeyImpl;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    64
import sun.nio.ch.Util;
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
    65
import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    66
import static sun.nio.ch.sctp.ResultContainer.SEND_FAILED;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    67
import static sun.nio.ch.sctp.ResultContainer.ASSOCIATION_CHANGED;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    68
import static sun.nio.ch.sctp.ResultContainer.PEER_ADDRESS_CHANGED;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
    69
import static sun.nio.ch.sctp.ResultContainer.SHUTDOWN;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
 * An implementation of an SctpChannel
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
public class SctpChannelImpl extends SctpChannel
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
    implements SelChImpl
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
{
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
    private final FileDescriptor fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
    private final int fdVal;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
    /* IDs of native threads doing send and receivess, for signalling */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
    private volatile long receiverThread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
    private volatile long senderThread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    /* Lock held by current receiving or connecting thread */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
    private final Object receiveLock = new Object();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
    /* Lock held by current sending or connecting thread */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
    private final Object sendLock = new Object();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
    private final ThreadLocal<Boolean> receiveInvoked =
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
        new ThreadLocal<Boolean>() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
             @Override protected Boolean initialValue() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
                 return Boolean.FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
    };
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
    /* Lock held by any thread that modifies the state fields declared below
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
       DO NOT invoke a blocking I/O operation while holding this lock! */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
    private final Object stateLock = new Object();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
    private enum ChannelState {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
        UNINITIALIZED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
        UNCONNECTED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
        PENDING,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
        CONNECTED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
        KILLPENDING,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
        KILLED,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
    /* -- The following fields are protected by stateLock -- */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
    private ChannelState state = ChannelState.UNINITIALIZED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
    /* Binding; Once bound the port will remain constant. */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
    int port = -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
    private HashSet<InetSocketAddress> localAddresses = new HashSet<InetSocketAddress>();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
    /* Has the channel been bound to the wildcard address */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
    private boolean wildcard; /* false */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
    //private InetSocketAddress remoteAddress = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
    /* Input/Output open */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
    private boolean readyToConnect;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
    /* Shutdown */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
    private boolean isShutdown;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
    private Association association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   128
    private Set<SocketAddress> remoteAddresses = Collections.emptySet();
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   129
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
    /* -- End of fields protected by stateLock -- */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
     * Constructor for normal connecting sockets
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
    public SctpChannelImpl(SelectorProvider provider) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
        //TODO: update provider remove public modifier
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
        super(provider);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
        this.fd = SctpNet.socket(true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
        this.fdVal = IOUtil.fdVal(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
        this.state = ChannelState.UNCONNECTED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
     * Constructor for sockets obtained from server sockets
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
    public SctpChannelImpl(SelectorProvider provider, FileDescriptor fd)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
         throws IOException {
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   148
        this(provider, fd, null);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   149
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   150
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   151
    /**
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   152
     * Constructor for sockets obtained from branching
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   153
     */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   154
    public SctpChannelImpl(SelectorProvider provider,
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   155
                           FileDescriptor fd,
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   156
                           Association association)
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   157
            throws IOException {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
        super(provider);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
        this.fd = fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
        this.fdVal = IOUtil.fdVal(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
        this.state = ChannelState.CONNECTED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
        port = (Net.localAddress(fd)).getPort();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   164
        if (association != null) { /* branched */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   165
            this.association = association;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   166
        } else { /* obtained from server channel */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   167
            /* Receive COMM_UP */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   168
            ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   169
            try {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   170
                receive(buf, null, null, true);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   171
            } finally {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   172
                Util.releaseTemporaryDirectBuffer(buf);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   173
            }
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
     * Binds the channel's socket to a local address.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
    public SctpChannel bind(SocketAddress local) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
        synchronized (receiveLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
            synchronized (sendLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
                synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
                    ensureOpenAndUnconnected();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
                    if (isBound())
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3320
diff changeset
   187
                        SctpNet.throwAlreadyBoundException();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
                    InetSocketAddress isa = (local == null) ?
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
                        new InetSocketAddress(0) : Net.checkAddress(local);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
                    Net.bind(fd, isa.getAddress(), isa.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
                    InetSocketAddress boundIsa = Net.localAddress(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
                    port = boundIsa.getPort();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
                    localAddresses.add(isa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
                    if (isa.getAddress().isAnyLocalAddress())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
                        wildcard = true;
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
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
    public SctpChannel bindAddress(InetAddress address)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
        bindUnbindAddress(address, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
        localAddresses.add(new InetSocketAddress(address, port));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
    public SctpChannel unbindAddress(InetAddress address)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
        bindUnbindAddress(address, false);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
        localAddresses.remove(new InetSocketAddress(address, port));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
    private SctpChannel bindUnbindAddress(InetAddress address, boolean add)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
        if (address == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
            throw new IllegalArgumentException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
        synchronized (receiveLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
            synchronized (sendLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
                synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
                    if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
                        throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
                    if (!isBound())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
                        throw new NotYetBoundException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
                    if (wildcard)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
                        throw new IllegalStateException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
                                "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
   233
                    if (address.isAnyLocalAddress())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
                        throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
                                "Cannot add or remove the wildcard address");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
                    if (add) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
                        for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
                            if (addr.getAddress().equals(address)) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3320
diff changeset
   239
                                SctpNet.throwAlreadyBoundException();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
                    } else { /*removing */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
                        /* Verify that there is more than one address
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
                         * and that address is already bound */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
                        if (localAddresses.size() <= 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
                            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
   247
                        boolean foundAddress = false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   248
                        for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   249
                            if (addr.getAddress().equals(address)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   250
                                foundAddress = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   251
                                break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   252
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   253
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   254
                        if (!foundAddress )
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   255
                            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
   256
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   257
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   258
                    SctpNet.bindx(fdVal, new InetAddress[]{address}, port, add);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   259
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   260
                    /* Update our internal Set to reflect the addition/removal */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   261
                    if (add)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   262
                        localAddresses.add(new InetSocketAddress(address, port));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   263
                    else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   264
                        for (InetSocketAddress addr : localAddresses) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   265
                            if (addr.getAddress().equals(address)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   266
                                localAddresses.remove(addr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   267
                                break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   268
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   269
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   270
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   271
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   272
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   273
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   274
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   275
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   276
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   277
    private boolean isBound() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   278
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   279
            return port == -1 ? false : true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   280
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   281
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   282
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   283
    private boolean isConnected() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   284
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   285
            return (state == ChannelState.CONNECTED);
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
    private void ensureOpenAndUnconnected() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   290
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   291
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   292
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   293
            if (isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   294
                throw new AlreadyConnectedException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   295
            if (state == ChannelState.PENDING)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   296
                throw new ConnectionPendingException();
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
    private boolean ensureReceiveOpen() throws ClosedChannelException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   301
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   302
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   303
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   304
            if (!isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   305
                throw new NotYetConnectedException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   306
            else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   307
                return true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   308
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   309
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   310
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   311
    private void ensureSendOpen() throws ClosedChannelException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   312
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   313
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   314
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   315
            if (isShutdown)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   316
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   317
            if (!isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   318
                throw new NotYetConnectedException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   319
        }
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
    private void receiverCleanup() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   323
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   324
            receiverThread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   325
            if (state == ChannelState.KILLPENDING)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   326
                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   327
        }
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
    private void senderCleanup() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   331
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   332
            senderThread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   333
            if (state == ChannelState.KILLPENDING)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   334
                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   335
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   336
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   337
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   338
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   339
    public Association association() throws ClosedChannelException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   340
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   341
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   342
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   343
            if (!isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   344
                return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   345
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   346
            return association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   347
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   348
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   349
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   350
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   351
    public boolean connect(SocketAddress endpoint) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   352
        synchronized (receiveLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   353
            synchronized (sendLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   354
                ensureOpenAndUnconnected();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   355
                InetSocketAddress isa = Net.checkAddress(endpoint);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   356
                SecurityManager sm = System.getSecurityManager();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   357
                if (sm != null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   358
                    sm.checkConnect(isa.getAddress().getHostAddress(),
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   359
                                    isa.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   360
                synchronized (blockingLock()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   361
                    int n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   362
                    try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   363
                        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   364
                            begin();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   365
                            synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   366
                                if (!isOpen()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   367
                                    return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   368
                                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   369
                                receiverThread = NativeThread.current();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   370
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   371
                            for (;;) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   372
                                InetAddress ia = isa.getAddress();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   373
                                if (ia.isAnyLocalAddress())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   374
                                    ia = InetAddress.getLocalHost();
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3320
diff changeset
   375
                                n = SctpNet.connect(fdVal, ia, isa.getPort());
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   376
                                if (  (n == IOStatus.INTERRUPTED)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   377
                                      && isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   378
                                    continue;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   379
                                break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   380
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   381
                        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   382
                            receiverCleanup();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   383
                            end((n > 0) || (n == IOStatus.UNAVAILABLE));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   384
                            assert IOStatus.check(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   385
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   386
                    } catch (IOException x) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   387
                        /* If an exception was thrown, close the channel after
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   388
                         * invoking end() so as to avoid bogus
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   389
                         * AsynchronousCloseExceptions */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   390
                        close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   391
                        throw x;
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
                    if (n > 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   395
                        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   396
                            /* Connection succeeded */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   397
                            state = ChannelState.CONNECTED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   398
                            if (!isBound()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   399
                                InetSocketAddress boundIsa =
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   400
                                        Net.localAddress(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   401
                                port = boundIsa.getPort();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   402
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   403
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   404
                            /* Receive COMM_UP */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   405
                            ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   406
                            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   407
                                receive(buf, null, null, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   408
                            } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   409
                                Util.releaseTemporaryDirectBuffer(buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   410
                            }
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   411
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   412
                            /* cache remote addresses */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   413
                            try {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   414
                                remoteAddresses = getRemoteAddresses();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   415
                            } catch (IOException unused) { /* swallow exception */ }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   416
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   417
                            return true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   418
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   419
                    } else  {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   420
                        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   421
                            /* If nonblocking and no exception then connection
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   422
                             * pending; disallow another invocation */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   423
                            if (!isBlocking())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   424
                                state = ChannelState.PENDING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   425
                            else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   426
                                assert false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   427
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   428
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   429
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   430
                return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   431
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   432
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   433
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   434
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   435
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   436
    public boolean connect(SocketAddress endpoint,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   437
                           int maxOutStreams,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   438
                           int maxInStreams)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   439
            throws IOException {
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   440
        ensureOpenAndUnconnected();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   441
        return setOption(SCTP_INIT_MAXSTREAMS, InitMaxStreams.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   442
                create(maxInStreams, maxOutStreams)).connect(endpoint);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   443
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   444
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   445
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   446
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   447
    public boolean isConnectionPending() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   448
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   449
            return (state == ChannelState.PENDING);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   450
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   451
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   452
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   453
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   454
    public boolean finishConnect() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   455
        synchronized (receiveLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   456
            synchronized (sendLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   457
                synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   458
                    if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   459
                        throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   460
                    if (isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   461
                        return true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   462
                    if (state != ChannelState.PENDING)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   463
                        throw new NoConnectionPendingException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   464
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   465
                int n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   466
                try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   467
                    try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   468
                        begin();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   469
                        synchronized (blockingLock()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   470
                            synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   471
                                if (!isOpen()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   472
                                    return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   473
                                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   474
                                receiverThread = NativeThread.current();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   475
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   476
                            if (!isBlocking()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   477
                                for (;;) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   478
                                    n = checkConnect(fd, false, readyToConnect);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   479
                                    if (  (n == IOStatus.INTERRUPTED)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   480
                                          && isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   481
                                        continue;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   482
                                    break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   483
                                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   484
                            } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   485
                                for (;;) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   486
                                    n = checkConnect(fd, true, readyToConnect);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   487
                                    if (n == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   488
                                        // Loop in case of
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   489
                                        // spurious notifications
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   490
                                        continue;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   491
                                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   492
                                    if (  (n == IOStatus.INTERRUPTED)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   493
                                          && isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   494
                                        continue;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   495
                                    break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   496
                                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   497
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   498
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   499
                    } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   500
                        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   501
                            receiverThread = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   502
                            if (state == ChannelState.KILLPENDING) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   503
                                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   504
                                /* poll()/getsockopt() does not report
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   505
                                 * error (throws exception, with n = 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   506
                                 * on Linux platform after dup2 and
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   507
                                 * signal-wakeup. Force n to 0 so the
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   508
                                 * end() can throw appropriate exception */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   509
                                n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   510
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   511
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   512
                        end((n > 0) || (n == IOStatus.UNAVAILABLE));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   513
                        assert IOStatus.check(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   514
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   515
                } catch (IOException x) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   516
                    /* If an exception was thrown, close the channel after
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   517
                     * invoking end() so as to avoid bogus
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   518
                     * AsynchronousCloseExceptions */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   519
                    close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   520
                    throw x;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   521
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   522
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   523
                if (n > 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   524
                    synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   525
                        state = ChannelState.CONNECTED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   526
                        if (!isBound()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   527
                            InetSocketAddress boundIsa =
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   528
                                    Net.localAddress(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   529
                            port = boundIsa.getPort();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   530
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   531
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   532
                        /* Receive COMM_UP */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   533
                        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   534
                        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   535
                            receive(buf, null, null, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   536
                        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   537
                            Util.releaseTemporaryDirectBuffer(buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   538
                        }
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   539
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   540
                        /* cache remote addresses */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   541
                        try {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   542
                            remoteAddresses = getRemoteAddresses();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   543
                        } catch (IOException unused) { /* swallow exception */ }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   544
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   545
                        return true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   546
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   547
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   548
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   549
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   550
        return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   551
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   552
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   553
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   554
    protected void implConfigureBlocking(boolean block) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   555
        IOUtil.configureBlocking(fd, block);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   556
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   557
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   558
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   559
    public void implCloseSelectableChannel() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   560
        synchronized (stateLock) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3320
diff changeset
   561
            SctpNet.preClose(fdVal);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   562
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   563
            if (receiverThread != 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   564
                NativeThread.signal(receiverThread);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   565
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   566
            if (senderThread != 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   567
                NativeThread.signal(senderThread);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   568
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   569
            if (!isRegistered())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   570
                kill();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   571
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   572
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   573
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   574
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   575
    public FileDescriptor getFD() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   576
        return fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   577
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   578
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   579
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   580
    public int getFDVal() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   581
        return fdVal;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   582
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   583
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   584
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   585
     * Translates native poll revent ops into a ready operation ops
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   586
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   587
    private boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   588
        int intOps = sk.nioInterestOps();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   589
        int oldOps = sk.nioReadyOps();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   590
        int newOps = initialOps;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   591
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   592
        if ((ops & Net.POLLNVAL) != 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   593
            /* This should only happen if this channel is pre-closed while a
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   594
             * selection operation is in progress
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   595
             * ## Throw an error if this channel has not been pre-closed */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   596
            return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   597
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   598
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   599
        if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   600
            newOps = intOps;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   601
            sk.nioReadyOps(newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   602
            /* No need to poll again in checkConnect,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   603
             * the error will be detected there */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   604
            readyToConnect = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   605
            return (newOps & ~oldOps) != 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   606
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   607
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   608
        if (((ops & Net.POLLIN) != 0) &&
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   609
            ((intOps & SelectionKey.OP_READ) != 0) &&
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   610
            isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   611
            newOps |= SelectionKey.OP_READ;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   612
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   613
        if (((ops & Net.POLLCONN) != 0) &&
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   614
            ((intOps & SelectionKey.OP_CONNECT) != 0) &&
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   615
            ((state == ChannelState.UNCONNECTED) || (state == ChannelState.PENDING))) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   616
            newOps |= SelectionKey.OP_CONNECT;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   617
            readyToConnect = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   618
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   619
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   620
        if (((ops & Net.POLLOUT) != 0) &&
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   621
            ((intOps & SelectionKey.OP_WRITE) != 0) &&
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   622
            isConnected())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   623
            newOps |= SelectionKey.OP_WRITE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   624
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   625
        sk.nioReadyOps(newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   626
        return (newOps & ~oldOps) != 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   627
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   628
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   629
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   630
    public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   631
        return translateReadyOps(ops, sk.nioReadyOps(), sk);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   632
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   633
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   634
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   635
    @SuppressWarnings("all")
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   636
    public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   637
        return translateReadyOps(ops, 0, sk);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   638
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   639
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   640
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   641
    public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   642
        int newOps = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   643
        if ((ops & SelectionKey.OP_READ) != 0)
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   644
            newOps |= Net.POLLIN;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   645
        if ((ops & SelectionKey.OP_WRITE) != 0)
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   646
            newOps |= Net.POLLOUT;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   647
        if ((ops & SelectionKey.OP_CONNECT) != 0)
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   648
            newOps |= Net.POLLCONN;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   649
        sk.selector.putEventOps(sk, newOps);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   650
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   651
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   652
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   653
    public void kill() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   654
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   655
            if (state == ChannelState.KILLED)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   656
                return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   657
            if (state == ChannelState.UNINITIALIZED) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   658
                state = ChannelState.KILLED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   659
                return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   660
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   661
            assert !isOpen() && !isRegistered();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   662
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   663
            /* Postpone the kill if there is a waiting reader
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   664
             * or writer thread. */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   665
            if (receiverThread == 0 && senderThread == 0) {
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3320
diff changeset
   666
                SctpNet.close(fdVal);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   667
                state = ChannelState.KILLED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   668
            } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   669
                state = ChannelState.KILLPENDING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   670
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   671
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   672
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   673
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   674
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   675
    public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   676
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   677
        if (name == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   678
            throw new NullPointerException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   679
        if (!supportedOptions().contains(name))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   680
            throw new UnsupportedOperationException("'" + name + "' not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   681
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   682
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   683
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   684
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   685
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   686
            SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   687
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   688
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   689
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   690
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   691
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   692
    @SuppressWarnings("unchecked")
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   693
    public <T> T getOption(SctpSocketOption<T> name) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   694
        if (name == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   695
            throw new NullPointerException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   696
        if (!supportedOptions().contains(name))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   697
            throw new UnsupportedOperationException("'" + name + "' not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   698
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   699
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   700
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   701
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   702
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   703
            return (T)SctpNet.getSocketOption(fdVal, name, 0 /*oneToOne*/);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   704
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   705
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   706
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   707
    private static class DefaultOptionsHolder {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   708
        static final Set<SctpSocketOption<?>> defaultOptions = defaultOptions();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   709
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   710
        private static Set<SctpSocketOption<?>> defaultOptions() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   711
            HashSet<SctpSocketOption<?>> set = new HashSet<SctpSocketOption<?>>(10);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   712
            set.add(SCTP_DISABLE_FRAGMENTS);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   713
            set.add(SCTP_EXPLICIT_COMPLETE);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   714
            set.add(SCTP_FRAGMENT_INTERLEAVE);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   715
            set.add(SCTP_INIT_MAXSTREAMS);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   716
            set.add(SCTP_NODELAY);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   717
            set.add(SCTP_PRIMARY_ADDR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   718
            set.add(SCTP_SET_PEER_PRIMARY_ADDR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   719
            set.add(SO_SNDBUF);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   720
            set.add(SO_RCVBUF);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   721
            set.add(SO_LINGER);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   722
            return Collections.unmodifiableSet(set);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   723
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   724
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   725
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   726
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   727
    public final Set<SctpSocketOption<?>> supportedOptions() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   728
        return DefaultOptionsHolder.defaultOptions;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   729
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   730
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   731
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   732
    public <T> MessageInfo receive(ByteBuffer buffer,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   733
                                   T attachment,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   734
                                   NotificationHandler<T> handler)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   735
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   736
        return receive(buffer, attachment, handler, false);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   737
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   738
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   739
    private <T> MessageInfo receive(ByteBuffer buffer,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   740
                                    T attachment,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   741
                                    NotificationHandler<T> handler,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   742
                                    boolean fromConnect)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   743
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   744
        if (buffer == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   745
            throw new IllegalArgumentException("buffer cannot be null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   746
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   747
        if (buffer.isReadOnly())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   748
            throw new IllegalArgumentException("Read-only buffer");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   749
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   750
        if (receiveInvoked.get())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   751
            throw new IllegalReceiveException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   752
                    "cannot invoke receive from handler");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   753
        receiveInvoked.set(Boolean.TRUE);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   754
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   755
        try {
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   756
            ResultContainer resultContainer = new ResultContainer();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   757
            do {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   758
                resultContainer.clear();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   759
                synchronized (receiveLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   760
                    if (!ensureReceiveOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   761
                        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   762
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   763
                    int n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   764
                    try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   765
                        begin();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   766
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   767
                        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   768
                            if(!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   769
                                return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   770
                            receiverThread = NativeThread.current();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   771
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   772
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   773
                        do {
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   774
                            n = receive(fdVal, buffer, resultContainer, fromConnect);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   775
                        } while ((n == IOStatus.INTERRUPTED) && isOpen());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   776
                    } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   777
                        receiverCleanup();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   778
                        end((n > 0) || (n == IOStatus.UNAVAILABLE));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   779
                        assert IOStatus.check(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   780
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   781
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   782
                    if (!resultContainer.isNotification()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   783
                        /* message or nothing */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   784
                        if (resultContainer.hasSomething()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   785
                            /* Set the association before returning */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   786
                            MessageInfoImpl info =
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   787
                                    resultContainer.getMessageInfo();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   788
                            synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   789
                                assert association != null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   790
                                info.setAssociation(association);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   791
                            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   792
                            return info;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   793
                        } else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   794
                            /* Non-blocking may return null if nothing available*/
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   795
                            return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   796
                    } else { /* notification */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   797
                        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   798
                            handleNotificationInternal(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   799
                                    resultContainer);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   800
                        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   801
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   802
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   803
                    if (fromConnect)  {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   804
                        /* If we reach here, then it was connect that invoked
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   805
                         * receive and received the COMM_UP. We have already
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   806
                         * handled the COMM_UP with the internal notification
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   807
                         * handler. Simply return. */
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   808
                        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   809
                    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   810
                }  /* receiveLock */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   811
            } while (handler == null ? true :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   812
                (invokeNotificationHandler(resultContainer, handler, attachment)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   813
                 == HandlerResult.CONTINUE));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   814
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   815
            return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   816
        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   817
            receiveInvoked.set(Boolean.FALSE);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   818
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   819
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   820
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   821
    private int receive(int fd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   822
                        ByteBuffer dst,
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   823
                        ResultContainer resultContainer,
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   824
                        boolean peek)
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   825
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   826
        int pos = dst.position();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   827
        int lim = dst.limit();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   828
        assert (pos <= lim);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   829
        int rem = (pos <= lim ? lim - pos : 0);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   830
        if (dst instanceof DirectBuffer && rem > 0)
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   831
            return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   832
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   833
        /* Substitute a native buffer */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   834
        int newSize = Math.max(rem, 1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   835
        ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   836
        try {
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   837
            int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   838
            bb.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   839
            if (n > 0 && rem > 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   840
                dst.put(bb);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   841
            return n;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   842
        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   843
            Util.releaseTemporaryDirectBuffer(bb);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   844
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   845
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   846
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   847
    private int receiveIntoNativeBuffer(int fd,
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   848
                                        ResultContainer resultContainer,
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   849
                                        ByteBuffer bb,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   850
                                        int rem,
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   851
                                        int pos,
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   852
                                        boolean peek)
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   853
        throws IOException
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   854
    {
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
   855
        int n = receive0(fd, resultContainer, ((DirectBuffer)bb).address() + pos, rem, peek);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   856
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   857
        if (n > 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   858
            bb.position(pos + n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   859
        return n;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   860
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   861
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   862
    private InternalNotificationHandler internalNotificationHandler =
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   863
            new InternalNotificationHandler();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   864
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   865
    private void handleNotificationInternal(ResultContainer resultContainer)
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   866
    {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   867
        invokeNotificationHandler(resultContainer,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   868
                internalNotificationHandler, null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   869
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   870
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   871
    private class InternalNotificationHandler
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   872
            extends AbstractNotificationHandler<Object>
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   873
    {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   874
        @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   875
        public HandlerResult handleNotification(
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   876
                AssociationChangeNotification not, Object unused) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   877
            if (not.event().equals(
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   878
                    AssociationChangeNotification.AssocChangeEvent.COMM_UP) &&
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   879
                    association == null) {
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   880
                AssociationChange sac = (AssociationChange) not;
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   881
                association = new AssociationImpl
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   882
                       (sac.assocId(), sac.maxInStreams(), sac.maxOutStreams());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   883
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   884
            return HandlerResult.CONTINUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   885
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   886
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   887
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   888
    private <T> HandlerResult invokeNotificationHandler
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
   889
                                 (ResultContainer resultContainer,
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   890
                                  NotificationHandler<T> handler,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   891
                                  T attachment) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   892
        SctpNotification notification = resultContainer.notification();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   893
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   894
            notification.setAssociation(association);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   895
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   896
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   897
        if (!(handler instanceof AbstractNotificationHandler)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   898
            return handler.handleNotification(notification, attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   899
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   900
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   901
        /* AbstractNotificationHandler */
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   902
        AbstractNotificationHandler<T> absHandler =
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
   903
                (AbstractNotificationHandler<T>)handler;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   904
        switch(resultContainer.type()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   905
            case ASSOCIATION_CHANGED :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   906
                return absHandler.handleNotification(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   907
                        resultContainer.getAssociationChanged(), attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   908
            case PEER_ADDRESS_CHANGED :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   909
                return absHandler.handleNotification(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   910
                        resultContainer.getPeerAddressChanged(), attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   911
            case SEND_FAILED :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   912
                return absHandler.handleNotification(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   913
                        resultContainer.getSendFailed(), attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   914
            case SHUTDOWN :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   915
                return absHandler.handleNotification(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   916
                        resultContainer.getShutdown(), attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   917
            default :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   918
                /* implementation specific handlers */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   919
                return absHandler.handleNotification(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   920
                        resultContainer.notification(), attachment);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   921
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   922
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   923
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   924
    private void checkAssociation(Association sendAssociation) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   925
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   926
            if (sendAssociation != null && !sendAssociation.equals(association)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   927
                throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   928
                        "Cannot send to another association");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   929
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   930
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   931
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   932
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   933
    private void checkStreamNumber(int streamNumber) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   934
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   935
            if (association != null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   936
                if (streamNumber < 0 ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   937
                      streamNumber >= association.maxOutboundStreams())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   938
                    throw new InvalidStreamException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   939
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   940
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   941
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   942
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   943
    /* TODO: Add support for ttl and isComplete to both 121 12M
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   944
     *       SCTP_EOR not yet supported on reference platforms
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   945
     *       TTL support limited...
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   946
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   947
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   948
    public int send(ByteBuffer buffer, MessageInfo messageInfo)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   949
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   950
        if (buffer == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   951
            throw new IllegalArgumentException("buffer cannot be null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   952
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   953
        if (messageInfo == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   954
            throw new IllegalArgumentException("messageInfo cannot be null");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   955
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   956
        checkAssociation(messageInfo.association());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   957
        checkStreamNumber(messageInfo.streamNumber());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   958
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   959
        synchronized (sendLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   960
            ensureSendOpen();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   961
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   962
            int n = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   963
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   964
                begin();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   965
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   966
                synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   967
                    if(!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   968
                        return 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   969
                    senderThread = NativeThread.current();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   970
                }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   971
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   972
                do {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   973
                    n = send(fdVal, buffer, messageInfo);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   974
                } while ((n == IOStatus.INTERRUPTED) && isOpen());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   975
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   976
                return IOStatus.normalize(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   977
            } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   978
                senderCleanup();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   979
                end((n > 0) || (n == IOStatus.UNAVAILABLE));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   980
                assert IOStatus.check(n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   981
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   982
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   983
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   984
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   985
    private int send(int fd, ByteBuffer src, MessageInfo messageInfo)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   986
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   987
        int streamNumber = messageInfo.streamNumber();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   988
        SocketAddress target = messageInfo.address();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   989
        boolean unordered = messageInfo.isUnordered();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   990
        int ppid = messageInfo.payloadProtocolID();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   991
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   992
        if (src instanceof DirectBuffer)
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   993
            return sendFromNativeBuffer(fd, src, target, streamNumber,
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   994
                    unordered, ppid);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   995
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   996
        /* Substitute a native buffer */
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   997
        int pos = src.position();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   998
        int lim = src.limit();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
   999
        assert (pos <= lim && streamNumber >= 0);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1000
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1001
        int rem = (pos <= lim ? lim - pos : 0);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1002
        ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1003
        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1004
            bb.put(src);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1005
            bb.flip();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1006
            /* Do not update src until we see how many bytes were written */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1007
            src.position(pos);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1008
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1009
            int n = sendFromNativeBuffer(fd, bb, target, streamNumber,
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1010
                    unordered, ppid);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1011
            if (n > 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1012
                /* now update src */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1013
                src.position(pos + n);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1014
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1015
            return n;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1016
        } finally {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1017
            Util.releaseTemporaryDirectBuffer(bb);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1018
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1019
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1020
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1021
    private int sendFromNativeBuffer(int fd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1022
                                     ByteBuffer bb,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1023
                                     SocketAddress target,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1024
                                     int streamNumber,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1025
                                     boolean unordered,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1026
                                     int ppid)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1027
            throws IOException {
16089
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1028
        InetAddress addr = null;     // no preferred address
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1029
        int port = 0;
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1030
        if (target != null) {
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1031
            InetSocketAddress isa = Net.checkAddress(target);
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1032
            addr = isa.getAddress();
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1033
            port = isa.getPort();
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1034
        }
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1035
4677
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1036
        int pos = bb.position();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1037
        int lim = bb.limit();
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1038
        assert (pos <= lim);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1039
        int rem = (pos <= lim ? lim - pos : 0);
1b6ce3fbc01b 6916890: (sctp) SctpChannel.send may cause IAE if given a heap buffer with an offset
chegar
parents: 4669
diff changeset
  1040
16089
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1041
        int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1042
                            port, -1 /*121*/, streamNumber, unordered, ppid);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1043
        if (written > 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1044
            bb.position(pos + written);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1045
        return written;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1046
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1047
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1048
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1049
    public SctpChannel shutdown() throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1050
        synchronized(stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1051
            if (isShutdown)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1052
                return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1053
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1054
            ensureSendOpen();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1055
            SctpNet.shutdown(fdVal, -1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1056
            if (senderThread != 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1057
                NativeThread.signal(senderThread);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1058
            isShutdown = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1059
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1060
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1061
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1062
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1063
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1064
    public Set<SocketAddress> getAllLocalAddresses()
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1065
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1066
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1067
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1068
                throw new ClosedChannelException();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1069
            if (!isBound())
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
  1070
                return Collections.emptySet();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1071
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1072
            return SctpNet.getLocalAddresses(fdVal);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1073
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1074
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1075
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1076
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1077
    public Set<SocketAddress> getRemoteAddresses()
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1078
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1079
        synchronized (stateLock) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1080
            if (!isOpen())
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1081
                throw new ClosedChannelException();
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1082
            if (!isConnected() || isShutdown)
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9679
diff changeset
  1083
                return Collections.emptySet();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1084
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1085
            try {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1086
                return SctpNet.getRemoteAddresses(fdVal, 0/*unused*/);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1087
            } catch (SocketException unused) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1088
                /* an open connected channel should always have remote addresses */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1089
                return remoteAddresses;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
  1090
            }
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1091
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1092
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1093
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1094
    /* Native */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1095
    private static native void initIDs();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1096
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 10137
diff changeset
  1097
    static native int receive0(int fd, ResultContainer resultContainer,
3320
a7c037dd2e14 6863110: Newly connected/accepted SctpChannel should fire OP_READ if registered with a Selector
chegar
parents: 3072
diff changeset
  1098
            long address, int length, boolean peek) throws IOException;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1099
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1100
    static native int send0(int fd, long address, int length,
16089
7cf1e2708454 7201071: InetSocketAddress serialization issue
chegar
parents: 12559
diff changeset
  1101
            InetAddress addr, int port, int assocId, int streamNumber,
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1102
            boolean unordered, int ppid) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1103
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1104
    private static native int checkConnect(FileDescriptor fd, boolean block,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1105
            boolean ready) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1106
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1107
    static {
19607
bee007586d06 8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents: 16100
diff changeset
  1108
        IOUtil.load();   /* loads nio & net native libraries */
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1109
        java.security.AccessController.doPrivileged(
12559
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1110
            new java.security.PrivilegedAction<Void>() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1111
                public Void run() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1112
                    System.loadLibrary("sctp");
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1113
                    return null;
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1114
                }
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 11823
diff changeset
  1115
            });
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1116
        initIDs();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1117
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
  1118
}