jdk/src/solaris/classes/sun/nio/ch/SctpNet.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4669 11d1dbd3598d
child 7545 409091945418
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4669
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
package sun.nio.ch;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
import java.io.FileDescriptor;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
import java.io.IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
import java.net.InetAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
import java.net.InetSocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
import java.net.SocketAddress;
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    32
import java.nio.channels.AlreadyBoundException;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
import java.util.Set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.HashSet;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.security.AccessController;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
import sun.security.action.GetPropertyAction;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import com.sun.nio.sctp.SctpSocketOption;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import static com.sun.nio.sctp.SctpStandardSocketOption.*;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
public class SctpNet {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
    static final String osName = AccessController.doPrivileged(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
                    new GetPropertyAction("os.name"));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
    /* -- Miscellaneous SCTP utilities -- */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
    static boolean bindxIPv4MappedAddresses() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
        if ("SunOS".equals(osName)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
            /* Solaris supports IPv4Mapped Addresses with bindx */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
            return true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
        } /* else {  //other OS/implementations  */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
        /* lksctp/linux requires Ipv4 addresses */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
        return false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    56
    static boolean throwAlreadyBoundException() throws IOException {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    57
        throw new AlreadyBoundException();
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    58
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    59
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    60
    static void listen(int fd, int backlog) throws IOException {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    61
        listen0(fd, backlog);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    62
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    63
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    64
    static int connect(int fd, InetAddress remote, int remotePort)
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    65
            throws IOException {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    66
        return connect0(fd, remote, remotePort);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    67
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    68
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    69
    static void close(int fd) throws IOException {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    70
        close0(fd);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    71
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    72
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    73
    static void preClose(int fd) throws IOException {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    74
        preClose0(fd);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    75
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    76
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
    /**
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    78
     * @param  oneToOne
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
     *         if {@code true} returns a one-to-one sctp socket, otherwise
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
     *         returns a one-to-many sctp socket
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
    static FileDescriptor socket(boolean oneToOne) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
        int nativefd = socket0(oneToOne);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
        return IOUtil.newFD(nativefd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
    static void bindx(int fd, InetAddress[] addrs, int port, boolean add)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
        bindx(fd, addrs, port, addrs.length, add,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
                bindxIPv4MappedAddresses());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
    static Set<SocketAddress> getLocalAddresses(int fd)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
        HashSet<SocketAddress> set = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
        SocketAddress[] saa = getLocalAddresses0(fd);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
        if (saa != null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
            set = new HashSet<SocketAddress>(saa.length);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
            for (SocketAddress sa : saa)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
                set.add(sa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
        return set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
    static Set<SocketAddress> getRemoteAddresses(int fd, int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
        HashSet<SocketAddress> set = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
        SocketAddress[] saa = getRemoteAddresses0(fd, assocId);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
        if (saa != null) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
            set = new HashSet<SocketAddress>(saa.length);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
            for (SocketAddress sa : saa)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
                set.add(sa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
        return set;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
    static void setSocketOption(int fd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
                                SctpSocketOption name,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
                                Object value,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
                                int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
        if (value == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
            throw new IllegalArgumentException("Invalid option value");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
        Class<?> type = name.type();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
        if (!type.isInstance(value))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
            throw new IllegalArgumentException("Invalid option value");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
        if (name.equals(SCTP_INIT_MAXSTREAMS)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
            InitMaxStreams maxStreamValue = (InitMaxStreams)value;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
            SctpNet.setInitMsgOption0(fd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
                 maxStreamValue.maxInStreams(), maxStreamValue.maxOutStreams());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
        } else if (name.equals(SCTP_PRIMARY_ADDR) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
                   name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
            SocketAddress addr  = (SocketAddress) value;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
            if (addr == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
                throw new IllegalArgumentException("Invalid option value");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
            Net.checkAddress(addr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
            InetSocketAddress netAddr = (InetSocketAddress)addr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
            if (name.equals(SCTP_PRIMARY_ADDR)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
                setPrimAddrOption0(fd, assocId,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
                        netAddr.getAddress(), netAddr.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
            } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
                setPeerPrimAddrOption0(fd, assocId,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
                        netAddr.getAddress(), netAddr.getPort());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
        } else if (name.equals(SCTP_DISABLE_FRAGMENTS) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   155
            name.equals(SCTP_EXPLICIT_COMPLETE) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
            name.equals(SCTP_FRAGMENT_INTERLEAVE) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
            name.equals(SCTP_NODELAY) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
            name.equals(SO_SNDBUF) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
            name.equals(SO_RCVBUF) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
            name.equals(SO_LINGER)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
            setIntOption(fd, name, value);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
            throw new AssertionError("Unknown socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
    static Object getSocketOption(int fd, SctpSocketOption name, int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
             throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
         if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
            throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
                    "SCTP_SET_PEER_PRIMARY_ADDR cannot be retrieved");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   172
        } else if (name.equals(SCTP_INIT_MAXSTREAMS)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   173
            /* container for holding maxIn/Out streams */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
            int[] values = new int[2];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
            SctpNet.getInitMsgOption0(fd, values);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
            return InitMaxStreams.create(values[0], values[1]);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
        } else if (name.equals(SCTP_PRIMARY_ADDR)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
            return getPrimAddrOption0(fd, assocId);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
        } else if (name.equals(SCTP_DISABLE_FRAGMENTS) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
            name.equals(SCTP_EXPLICIT_COMPLETE) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
            name.equals(SCTP_FRAGMENT_INTERLEAVE) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
            name.equals(SCTP_NODELAY) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
            name.equals(SO_SNDBUF) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
            name.equals(SO_RCVBUF) ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
            name.equals(SO_LINGER)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
            return getIntOption(fd, name);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
            throw new AssertionError("Unknown socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
    static void setIntOption(int fd, SctpSocketOption name, Object value)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
        if (value == null)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
            throw new IllegalArgumentException("Invalid option value");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   196
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   197
        Class<?> type = name.type();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   198
        if (type != Integer.class && type != Boolean.class)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
            throw new AssertionError("Should not reach here");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
        if (name == SO_RCVBUF ||
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
            name == SO_SNDBUF)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
        {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
            int i = ((Integer)value).intValue();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
            if (i < 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
                throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
                        "Invalid send/receive buffer size");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
        } else if (name == SO_LINGER) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
            int i = ((Integer)value).intValue();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
            if (i < 0)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
                value = Integer.valueOf(-1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
            if (i > 65535)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
                value = Integer.valueOf(65535);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
        } else if (name.equals(SCTP_FRAGMENT_INTERLEAVE)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
            int i = ((Integer)value).intValue();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
            if (i < 0 || i > 2)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
                throw new IllegalArgumentException(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
                        "Invalid value for SCTP_FRAGMENT_INTERLEAVE");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
        int arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
        if (type == Integer.class) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
            arg = ((Integer)value).intValue();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
            boolean b = ((Boolean)value).booleanValue();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
            arg = (b) ? 1 : 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
        setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
    static Object getIntOption(int fd, SctpSocketOption name)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
        Class<?> type = name.type();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
        if (type != Integer.class && type != Boolean.class)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
            throw new AssertionError("Should not reach here");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
        if (!(name instanceof SctpStdSocketOption))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
            throw new AssertionError("Should not reach here");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
        int value = getIntOption0(fd,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
                ((SctpStdSocketOption)name).constValue());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
        if (type == Integer.class) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
            return Integer.valueOf(value);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   247
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   248
            return (value == 0) ? Boolean.FALSE : Boolean.TRUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   249
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   250
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   251
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   252
    static void shutdown(int fd, int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   253
            throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   254
        shutdown0(fd, assocId);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   255
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   256
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   257
    static FileDescriptor branch(int fd, int assocId) throws IOException {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   258
        int nativefd = branch0(fd, assocId);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   259
        return IOUtil.newFD(nativefd);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   260
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   261
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   262
    /* Native Methods */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   263
    static native int socket0(boolean oneToOne) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   264
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   265
    static native void listen0(int fd, int backlog) throws IOException;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   266
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   267
    static native int connect0(int fd, InetAddress remote, int remotePort)
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   268
        throws IOException;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   269
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   270
    static native void close0(int fd) throws IOException;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   271
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   272
    static native void preClose0(int fd) throws IOException;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   273
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   274
    static native void bindx(int fd, InetAddress[] addrs, int port, int length,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   275
            boolean add, boolean preferIPv6) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   276
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   277
    static native int getIntOption0(int fd, int opt) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   278
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   279
    static native void setIntOption0(int fd, int opt, int arg)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   280
        throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   281
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   282
    static native SocketAddress[] getLocalAddresses0(int fd) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   283
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   284
    static native SocketAddress[] getRemoteAddresses0(int fd, int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   285
            throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   286
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   287
    static native int branch0(int fd, int assocId) throws IOException;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   288
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   289
    static native void setPrimAddrOption0(int fd, int assocId, InetAddress ia,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   290
            int port) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   291
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   292
    static native void setPeerPrimAddrOption0(int fd, int assocId,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   293
            InetAddress ia, int port) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   294
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   295
    static native SocketAddress getPrimAddrOption0(int fd, int assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   296
            throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   297
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   298
    /* retVals [0] maxInStreams, [1] maxOutStreams */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   299
    static native void getInitMsgOption0(int fd, int[] retVals) throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   300
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   301
    static native void setInitMsgOption0(int fd, int arg1, int arg2)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   302
            throws IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   303
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   304
    static native void shutdown0(int fd, int assocId);
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   305
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   306
    static native void init();
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   307
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   308
    static {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   309
        init();
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   310
    }
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   311
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   312