0N/A/*
3793N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage com.sun.nio.sctp;
0N/A
0N/Aimport java.net.SocketAddress;
0N/Aimport sun.nio.ch.SctpStdSocketOption;
3424N/A
3424N/A/**
3424N/A * SCTP channels supports the socket options defined by this class
0N/A * (as well as those listed in the particular channel class) and may support
0N/A * additional Implementation specific socket options.
0N/A *
0N/A * @since 1.7
0N/A */
0N/Apublic class SctpStandardSocketOptions {
0N/A private SctpStandardSocketOptions() {}
0N/A /**
0N/A * Enables or disables message fragmentation.
3867N/A *
0N/A * <P> The value of this socket option is a {@code Boolean} that represents
0N/A * whether the option is enabled or disabled. If enabled no SCTP message
0N/A * fragmentation will be performed. Instead if a message being sent
0N/A * exceeds the current PMTU size, the message will NOT be sent and
0N/A * an error will be indicated to the user.
0N/A *
0N/A * <P> It is implementation specific whether or not this option is
0N/A * supported.
0N/A */
0N/A public static final SctpSocketOption<Boolean> SCTP_DISABLE_FRAGMENTS = new
0N/A SctpStdSocketOption<Boolean>("SCTP_DISABLE_FRAGMENTS", Boolean.class,
2384N/A sun.nio.ch.SctpStdSocketOption.SCTP_DISABLE_FRAGMENTS);
0N/A
0N/A /**
0N/A * Enables or disables explicit message completion.
2476N/A *
2476N/A * <p> The value of this socket option is a {@code Boolean} that represents
2476N/A * whether the option is enabled or disabled. When this option is enabled,
3686N/A * the {@code send} method may be invoked multiple times to a send message.
2476N/A * The {@code isComplete} parameter of the {@link MessageInfo} must only
3689N/A * be set to {@code true} for the final send to indicate that the message is
4352N/A * complete. If this option is disabled then each individual {@code send}
4352N/A * invocation is considered complete.
2476N/A *
0N/A * <P> The default value of the option is {@code false} indicating that the
0N/A * option is disabled. It is implementation specific whether or not this
0N/A * option is supported.
0N/A */
0N/A public static final SctpSocketOption<Boolean> SCTP_EXPLICIT_COMPLETE = new
0N/A SctpStdSocketOption<Boolean>("SCTP_EXPLICIT_COMPLETE", Boolean.class,
0N/A sun.nio.ch.SctpStdSocketOption.SCTP_EXPLICIT_COMPLETE);
0N/A
0N/A /**
0N/A * Fragmented interleave controls how the presentation of messages occur
0N/A * for the message receiver. There are three levels of fragment interleave
0N/A * defined. Two of the levels effect {@link SctpChannel}, while
463N/A * {@link SctpMultiChannel} is effected by all three levels.
0N/A *
463N/A * <P> This option takes an {@code Integer} value. It can be set to a value
463N/A * of {@code 0}, {@code 1} or {@code 2}.
463N/A *
0N/A * <P> Setting the three levels provides the following receiver
3420N/A * interactions:
3420N/A *
0N/A * <P> {@code level 0} - Prevents the interleaving of any messages. This
3698N/A * means that when a partial delivery begins, no other messages will be
3689N/A * received except the message being partially delivered. If another message
4157N/A * arrives on a different stream (or association) that could be delivered,
4157N/A * it will be blocked waiting for the user to read all of the partially
0N/A * delivered message.
3420N/A *
0N/A * <P> {@code level 1} - Allows interleaving of messages that are from
3420N/A * different associations. For {@code SctpChannel}, level 0 and
0N/A * level 1 have the same meaning since an {@code SctpChannel} always
0N/A * receives messages from the same association. Note that setting an {@code
0N/A * SctpMultiChannel} to this level may cause multiple partial
0N/A * delivers from different associations but for any given association, only
3420N/A * one message will be delivered until all parts of a message have been
3420N/A * delivered. This means that one large message, being read with an
0N/A * association identification of "X", will block other messages from
0N/A * association "X" from being delivered.
0N/A *
0N/A * <P> {@code level 2} - Allows complete interleaving of messages. This
0N/A * level requires that the sender carefully observe not only the peer
0N/A * {@code Association} but also must pay careful attention to the stream
0N/A * number. With this option enabled a partially delivered message may begin
0N/A * being delivered for association "X" stream "Y" and the next subsequent
0N/A * receive may return a message from association "X" stream "Z". Note that
0N/A * no other messages would be delivered for association "X" stream "Y"
0N/A * until all of stream "Y"'s partially delivered message was read.
0N/A * Note that this option effects both channel types. Also note that
0N/A * for an {@code SctpMultiChannel} not only may another streams
0N/A * message from the same association be delivered from the next receive,
0N/A * some other associations message may be delivered upon the next receive.
0N/A *
0N/A * <P> It is implementation specific whether or not this option is
0N/A * supported.
0N/A */
0N/A public static final SctpSocketOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
0N/A new SctpStdSocketOption<Integer>("SCTP_FRAGMENT_INTERLEAVE",
0N/A Integer.class,
0N/A sun.nio.ch.SctpStdSocketOption.SCTP_FRAGMENT_INTERLEAVE);
0N/A
3525N/A /**
0N/A * The maximum number of streams requested by the local endpoint during
0N/A * association initialization.
0N/A *
0N/A * <P> The value of this socket option is an {@link
0N/A * SctpStandardSocketOptions.InitMaxStreams InitMaxStreams}, that represents
0N/A * the maximum number of inbound and outbound streams that an association
0N/A * on the channel is prepared to support.
0N/A *
0N/A * <P> For an {@link SctpChannel} this option may only be used to
0N/A * change the number of inbound/outbound streams prior to connecting.
0N/A *
0N/A * <P> For an {@link SctpMultiChannel} this option determines
0N/A * the maximum number of inbound/outbound streams new associations setup
0N/A * on the channel will be prepared to support.
0N/A *
0N/A * <P> For an {@link SctpServerChannel} this option determines the
0N/A * maximum number of inbound/outbound streams accepted sockets will
0N/A * negotiate with their connecting peer.
0N/A *
0N/A * <P> In all cases the value set by this option is used in the negotiation
0N/A * of new associations setup on the channel's socket and the actual
0N/A * maximum number of inbound/outbound streams that have been negotiated
0N/A * with the peer can be retrieved from the appropriate {@link
0N/A * Association}. The {@code Association} can be retrieved from the
0N/A * {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP COMM_UP}
0N/A * {@link AssociationChangeNotification} belonging to that association.
0N/A *
0N/A * <p> This value is bounded by the actual implementation. In other
0N/A * words the user may be able to support more streams than the Operating
0N/A * System. In such a case, the Operating System limit may override the
0N/A * value requested by the user. The default value of 0 indicates to use
0N/A * the endpoints default value.
0N/A */
0N/A public static final SctpSocketOption
0N/A <SctpStandardSocketOptions.InitMaxStreams> SCTP_INIT_MAXSTREAMS =
0N/A new SctpStdSocketOption<SctpStandardSocketOptions.InitMaxStreams>(
0N/A "SCTP_INIT_MAXSTREAMS", SctpStandardSocketOptions.InitMaxStreams.class);
0N/A
0N/A /**
0N/A * Enables or disables a Nagle-like algorithm.
0N/A *
0N/A * <P> The value of this socket option is a {@code Boolean} that represents
4048N/A * whether the option is enabled or disabled. SCTP uses an algorithm like
0N/A * <em>The Nagle Algorithm</em> to coalesce short segments and
0N/A * improve network efficiency.
0N/A */
0N/A public static final SctpSocketOption<Boolean> SCTP_NODELAY =
0N/A new SctpStdSocketOption<Boolean>("SCTP_NODELAY", Boolean.class,
0N/A sun.nio.ch.SctpStdSocketOption.SCTP_NODELAY);
0N/A
0N/A /**
0N/A * Requests that the local SCTP stack use the given peer address as
0N/A * the association primary.
0N/A *
0N/A * <P> The value of this socket option is a {@code SocketAddress}
0N/A * that represents the peer address that the local SCTP stack should use as
0N/A * the association primary. The address must be one of the association
0N/A * peer's addresses.
0N/A *
3424N/A * <P> An {@code SctpMultiChannel} can control more than one
0N/A * association, the association parameter must be given when setting or
0N/A * retrieving this option.
0N/A *
0N/A * <P> Since {@code SctpChannel} only controls one association,
0N/A * the association parameter is not required and this option can be
0N/A * set or queried directly.
0N/A */
0N/A public static final SctpSocketOption<SocketAddress> SCTP_PRIMARY_ADDR =
4048N/A new SctpStdSocketOption<SocketAddress>
0N/A ("SCTP_PRIMARY_ADDR", SocketAddress.class);
0N/A
0N/A /**
3867N/A * Requests that the peer mark the enclosed address as the association
3867N/A * primary.
3867N/A *
3867N/A * <P> The value of this socket option is a {@code SocketAddress}
3867N/A * that represents the local address that the peer should use as its
3867N/A * primary address. The given address must be one of the association's
3867N/A * locally bound addresses.
3867N/A *
3867N/A * <P> An {@code SctpMultiChannel} can control more than one
3867N/A * association, the association parameter must be given when setting or
0N/A * retrieving this option.
0N/A *
0N/A * <P> Since {@code SctpChannel} only controls one association,
0N/A * the association parameter is not required and this option can be
0N/A * queried directly.
0N/A *
0N/A * <P> Note, this is a set only option and cannot be retrieved by {@code
0N/A * getOption}. It is implementation specific whether or not this
0N/A * option is supported.
0N/A */
0N/A public static final SctpSocketOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
0N/A new SctpStdSocketOption<SocketAddress>
0N/A ("SCTP_SET_PEER_PRIMARY_ADDR", SocketAddress.class);
0N/A
0N/A /**
0N/A * The size of the socket send buffer.
3424N/A *
0N/A * <p> The value of this socket option is an {@code Integer} that is the
0N/A * size of the socket send buffer in bytes. The socket send buffer is an
0N/A * output buffer used by the networking implementation. It may need to be
0N/A * increased for high-volume connections. The value of the socket option is
0N/A * a <em>hint</em> to the implementation to size the buffer and the actual
0N/A * size may differ. The socket option can be queried to retrieve the actual
0N/A * size.
0N/A *
0N/A * <p> For {@code SctpChannel}, this controls the amount of data
3424N/A * the SCTP stack may have waiting in internal buffers to be sent. This
3867N/A * option therefore bounds the maximum size of data that can be sent in a
0N/A * single send call.
0N/A *
3424N/A * <P> For {@code SctpMultiChannel}, the effect is the same as for {@code
3424N/A * SctpChannel}, except that it applies to all associations. The option
0N/A * applies to each association's window size separately.
0N/A *
0N/A * <p> An implementation allows this socket option to be set before the
0N/A * socket is bound or connected. Whether an implementation allows the
0N/A * socket send buffer to be changed after the socket is bound is system
0N/A * dependent.
0N/A */
0N/A public static final SctpSocketOption<Integer> SO_SNDBUF =
0N/A new SctpStdSocketOption<Integer>("SO_SNDBUF", Integer.class,
0N/A sun.nio.ch.SctpStdSocketOption.SO_SNDBUF);
0N/A
0N/A /**
0N/A * The size of the socket receive buffer.
0N/A *
0N/A * <P> The value of this socket option is an {@code Integer} that is the
0N/A * size of the socket receive buffer in bytes. The socket receive buffer is
0N/A * an input buffer used by the networking implementation. It may need to be
0N/A * increased for high-volume connections or decreased to limit the possible
0N/A * backlog of incoming data. The value of the socket option is a
0N/A * <em>hint</em> to the implementation to size the buffer and the actual
0N/A * size may differ.
0N/A *
0N/A * <P> For {@code SctpChannel}, this controls the receiver window size.
0N/A *
0N/A * <P> For {@code SctpMultiChannel}, the meaning is implementation
0N/A * dependent. It might control the receive buffer for each association bound
0N/A * to the socket descriptor or it might control the receive buffer for the
0N/A * whole socket.
0N/A *
0N/A * <p> An implementation allows this socket option to be set before the
0N/A * socket is bound or connected. Whether an implementation allows the
0N/A * socket receive buffer to be changed after the socket is bound is system
0N/A * dependent.
0N/A */
0N/A public static final SctpSocketOption<Integer> SO_RCVBUF =
0N/A new SctpStdSocketOption<Integer>("SO_RCVBUF", Integer.class,
0N/A sun.nio.ch.SctpStdSocketOption.SO_RCVBUF);
0N/A
0N/A /**
0N/A * Linger on close if data is present.
0N/A *
0N/A * <p> The value of this socket option is an {@code Integer} that controls
0N/A * the action taken when unsent data is queued on the socket and a method
0N/A * to close the socket is invoked. If the value of the socket option is zero
0N/A * or greater, then it represents a timeout value, in seconds, known as the
0N/A * <em>linger interval</em>. The linger interval is the timeout for the
0N/A * {@code close} method to block while the operating system attempts to
0N/A * transmit the unsent data or it decides that it is unable to transmit the
0N/A * data. If the value of the socket option is less than zero then the option
0N/A * is disabled. In that case the {@code close} method does not wait until
0N/A * unsent data is transmitted; if possible the operating system will transmit
0N/A * any unsent data before the connection is closed.
0N/A *
0N/A * <p> This socket option is intended for use with sockets that are configured
0N/A * in {@link java.nio.channels.SelectableChannel#isBlocking() blocking} mode
0N/A * only. The behavior of the {@code close} method when this option is
0N/A * enabled on a non-blocking socket is not defined.
0N/A *
0N/A * <p> The initial value of this socket option is a negative value, meaning
0N/A * that the option is disabled. The option may be enabled, or the linger
0N/A * interval changed, at any time. The maximum value of the linger interval
0N/A * is system dependent. Setting the linger interval to a value that is
0N/A * greater than its maximum value causes the linger interval to be set to
0N/A * its maximum value.
0N/A */
0N/A public static final SctpSocketOption<Integer> SO_LINGER =
0N/A new SctpStdSocketOption<Integer>("SO_LINGER", Integer.class,
0N/A sun.nio.ch.SctpStdSocketOption.SO_LINGER);
1776N/A
0N/A /**
0N/A * This class is used to set the maximum number of inbound/outbound streams
0N/A * used by the local endpoint during association initialization. An
0N/A * instance of this class is used to set the {@link
0N/A * SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS SCTP_INIT_MAXSTREAMS}
0N/A * socket option.
0N/A *
0N/A * @since 1.7
0N/A */
0N/A public static class InitMaxStreams {
0N/A private int maxInStreams;
0N/A private int maxOutStreams;
0N/A
0N/A private InitMaxStreams(int maxInStreams, int maxOutStreams) {
0N/A this.maxInStreams = maxInStreams;
0N/A this.maxOutStreams = maxOutStreams;
0N/A }
0N/A
0N/A /**
0N/A * Creates an InitMaxStreams instance.
0N/A *
0N/A * @param maxInStreams
0N/A * The maximum number of inbound streams, where
0N/A * {@code 0 <= maxInStreams <= 65536}
0N/A *
0N/A * @param maxOutStreams
0N/A * The maximum number of outbound streams, where
0N/A * {@code 0 <= maxOutStreams <= 65536}
0N/A *
0N/A * @return An {@code InitMaxStreams} instance
0N/A *
0N/A * @throws IllegalArgumentException
0N/A * If an argument is outside of specified bounds
0N/A */
0N/A public static InitMaxStreams create
0N/A (int maxInStreams, int maxOutStreams) {
0N/A if (maxOutStreams < 0 || maxOutStreams > 65535)
0N/A throw new IllegalArgumentException(
350N/A "Invalid maxOutStreams value");
0N/A if (maxInStreams < 0 || maxInStreams > 65535)
0N/A throw new IllegalArgumentException(
0N/A "Invalid maxInStreams value");
0N/A
0N/A return new InitMaxStreams(maxInStreams, maxOutStreams);
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum number of inbound streams.
350N/A *
0N/A * @return Maximum inbound streams
0N/A */
0N/A public int maxInStreams() {
0N/A return maxInStreams;
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum number of outbound streams.
0N/A *
0N/A * @return Maximum outbound streams
0N/A */
0N/A public int maxOutStreams() {
0N/A return maxOutStreams;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this init max streams, including
0N/A * the maximum in and out bound streams.
0N/A *
0N/A * @return A string representation of this init max streams
0N/A */
1311N/A @Override
0N/A public String toString() {
0N/A StringBuilder sb = new StringBuilder();
0N/A sb.append(super.toString()).append(" [");
0N/A sb.append("maxInStreams:").append(maxInStreams);
0N/A sb.append("maxOutStreams:").append(maxOutStreams).append("]");
0N/A return sb.toString();
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the specified object is another {@code InitMaxStreams}
0N/A * instance with the same number of in and out bound streams.
0N/A *
0N/A * @param obj
0N/A * The object to be compared with this init max streams
0N/A *
0N/A * @return true if the specified object is another
0N/A * {@code InitMaxStreams} instance with the same number of in
0N/A * and out bound streams
0N/A */
0N/A @Override
0N/A public boolean equals(Object obj) {
0N/A if (obj != null && obj instanceof InitMaxStreams) {
0N/A InitMaxStreams that = (InitMaxStreams) obj;
0N/A if (this.maxInStreams == that.maxInStreams &&
0N/A this.maxOutStreams == that.maxOutStreams)
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns a hash code value for this init max streams.
0N/A */
0N/A @Override
0N/A public int hashCode() {
0N/A int hash = 7 ^ maxInStreams ^ maxOutStreams;
0N/A return hash;
0N/A }
0N/A }
0N/A}
0N/A