Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/nio/sctp/SctpStandardSocketOptions.java
38923 views
/*1* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.nio.sctp;2526import java.net.SocketAddress;27import sun.nio.ch.sctp.SctpStdSocketOption;2829/**30* SCTP channels supports the socket options defined by this class31* (as well as those listed in the particular channel class) and may support32* additional Implementation specific socket options.33*34* @since 1.735*/36@jdk.Exported37public class SctpStandardSocketOptions {38private SctpStandardSocketOptions() {}39/**40* Enables or disables message fragmentation.41*42* <P> The value of this socket option is a {@code Boolean} that represents43* whether the option is enabled or disabled. If enabled no SCTP message44* fragmentation will be performed. Instead if a message being sent45* exceeds the current PMTU size, the message will NOT be sent and46* an error will be indicated to the user.47*48* <P> It is implementation specific whether or not this option is49* supported.50*/51public static final SctpSocketOption<Boolean> SCTP_DISABLE_FRAGMENTS = new52SctpStdSocketOption<Boolean>("SCTP_DISABLE_FRAGMENTS", Boolean.class,53sun.nio.ch.sctp.SctpStdSocketOption.SCTP_DISABLE_FRAGMENTS);5455/**56* Enables or disables explicit message completion.57*58* <p> The value of this socket option is a {@code Boolean} that represents59* whether the option is enabled or disabled. When this option is enabled,60* the {@code send} method may be invoked multiple times to a send message.61* The {@code isComplete} parameter of the {@link MessageInfo} must only62* be set to {@code true} for the final send to indicate that the message is63* complete. If this option is disabled then each individual {@code send}64* invocation is considered complete.65*66* <P> The default value of the option is {@code false} indicating that the67* option is disabled. It is implementation specific whether or not this68* option is supported.69*/70public static final SctpSocketOption<Boolean> SCTP_EXPLICIT_COMPLETE = new71SctpStdSocketOption<Boolean>("SCTP_EXPLICIT_COMPLETE", Boolean.class,72sun.nio.ch.sctp.SctpStdSocketOption.SCTP_EXPLICIT_COMPLETE);7374/**75* Fragmented interleave controls how the presentation of messages occur76* for the message receiver. There are three levels of fragment interleave77* defined. Two of the levels effect {@link SctpChannel}, while78* {@link SctpMultiChannel} is effected by all three levels.79*80* <P> This option takes an {@code Integer} value. It can be set to a value81* of {@code 0}, {@code 1} or {@code 2}.82*83* <P> Setting the three levels provides the following receiver84* interactions:85*86* <P> {@code level 0} - Prevents the interleaving of any messages. This87* means that when a partial delivery begins, no other messages will be88* received except the message being partially delivered. If another message89* arrives on a different stream (or association) that could be delivered,90* it will be blocked waiting for the user to read all of the partially91* delivered message.92*93* <P> {@code level 1} - Allows interleaving of messages that are from94* different associations. For {@code SctpChannel}, level 0 and95* level 1 have the same meaning since an {@code SctpChannel} always96* receives messages from the same association. Note that setting an {@code97* SctpMultiChannel} to this level may cause multiple partial98* delivers from different associations but for any given association, only99* one message will be delivered until all parts of a message have been100* delivered. This means that one large message, being read with an101* association identification of "X", will block other messages from102* association "X" from being delivered.103*104* <P> {@code level 2} - Allows complete interleaving of messages. This105* level requires that the sender carefully observe not only the peer106* {@code Association} but also must pay careful attention to the stream107* number. With this option enabled a partially delivered message may begin108* being delivered for association "X" stream "Y" and the next subsequent109* receive may return a message from association "X" stream "Z". Note that110* no other messages would be delivered for association "X" stream "Y"111* until all of stream "Y"'s partially delivered message was read.112* Note that this option effects both channel types. Also note that113* for an {@code SctpMultiChannel} not only may another streams114* message from the same association be delivered from the next receive,115* some other associations message may be delivered upon the next receive.116*117* <P> It is implementation specific whether or not this option is118* supported.119*/120public static final SctpSocketOption<Integer> SCTP_FRAGMENT_INTERLEAVE =121new SctpStdSocketOption<Integer>("SCTP_FRAGMENT_INTERLEAVE",122Integer.class,123sun.nio.ch.sctp.SctpStdSocketOption.SCTP_FRAGMENT_INTERLEAVE);124125/**126* The maximum number of streams requested by the local endpoint during127* association initialization.128*129* <P> The value of this socket option is an {@link130* SctpStandardSocketOptions.InitMaxStreams InitMaxStreams}, that represents131* the maximum number of inbound and outbound streams that an association132* on the channel is prepared to support.133*134* <P> For an {@link SctpChannel} this option may only be used to135* change the number of inbound/outbound streams prior to connecting.136*137* <P> For an {@link SctpMultiChannel} this option determines138* the maximum number of inbound/outbound streams new associations setup139* on the channel will be prepared to support.140*141* <P> For an {@link SctpServerChannel} this option determines the142* maximum number of inbound/outbound streams accepted sockets will143* negotiate with their connecting peer.144*145* <P> In all cases the value set by this option is used in the negotiation146* of new associations setup on the channel's socket and the actual147* maximum number of inbound/outbound streams that have been negotiated148* with the peer can be retrieved from the appropriate {@link149* Association}. The {@code Association} can be retrieved from the150* {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP COMM_UP}151* {@link AssociationChangeNotification} belonging to that association.152*153* <p> This value is bounded by the actual implementation. In other154* words the user may be able to support more streams than the Operating155* System. In such a case, the Operating System limit may override the156* value requested by the user. The default value of 0 indicates to use157* the endpoints default value.158*/159public static final SctpSocketOption160<SctpStandardSocketOptions.InitMaxStreams> SCTP_INIT_MAXSTREAMS =161new SctpStdSocketOption<SctpStandardSocketOptions.InitMaxStreams>(162"SCTP_INIT_MAXSTREAMS", SctpStandardSocketOptions.InitMaxStreams.class);163164/**165* Enables or disables a Nagle-like algorithm.166*167* <P> The value of this socket option is a {@code Boolean} that represents168* whether the option is enabled or disabled. SCTP uses an algorithm like169* <em>The Nagle Algorithm</em> to coalesce short segments and170* improve network efficiency.171*/172public static final SctpSocketOption<Boolean> SCTP_NODELAY =173new SctpStdSocketOption<Boolean>("SCTP_NODELAY", Boolean.class,174sun.nio.ch.sctp.SctpStdSocketOption.SCTP_NODELAY);175176/**177* Requests that the local SCTP stack use the given peer address as178* the association primary.179*180* <P> The value of this socket option is a {@code SocketAddress}181* that represents the peer address that the local SCTP stack should use as182* the association primary. The address must be one of the association183* peer's addresses.184*185* <P> An {@code SctpMultiChannel} can control more than one186* association, the association parameter must be given when setting or187* retrieving this option.188*189* <P> Since {@code SctpChannel} only controls one association,190* the association parameter is not required and this option can be191* set or queried directly.192*/193public static final SctpSocketOption<SocketAddress> SCTP_PRIMARY_ADDR =194new SctpStdSocketOption<SocketAddress>195("SCTP_PRIMARY_ADDR", SocketAddress.class);196197/**198* Requests that the peer mark the enclosed address as the association199* primary.200*201* <P> The value of this socket option is a {@code SocketAddress}202* that represents the local address that the peer should use as its203* primary address. The given address must be one of the association's204* locally bound addresses.205*206* <P> An {@code SctpMultiChannel} can control more than one207* association, the association parameter must be given when setting or208* retrieving this option.209*210* <P> Since {@code SctpChannel} only controls one association,211* the association parameter is not required and this option can be212* queried directly.213*214* <P> Note, this is a set only option and cannot be retrieved by {@code215* getOption}. It is implementation specific whether or not this216* option is supported.217*/218public static final SctpSocketOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =219new SctpStdSocketOption<SocketAddress>220("SCTP_SET_PEER_PRIMARY_ADDR", SocketAddress.class);221222/**223* The size of the socket send buffer.224*225* <p> The value of this socket option is an {@code Integer} that is the226* size of the socket send buffer in bytes. The socket send buffer is an227* output buffer used by the networking implementation. It may need to be228* increased for high-volume connections. The value of the socket option is229* a <em>hint</em> to the implementation to size the buffer and the actual230* size may differ. The socket option can be queried to retrieve the actual231* size.232*233* <p> For {@code SctpChannel}, this controls the amount of data234* the SCTP stack may have waiting in internal buffers to be sent. This235* option therefore bounds the maximum size of data that can be sent in a236* single send call.237*238* <P> For {@code SctpMultiChannel}, the effect is the same as for {@code239* SctpChannel}, except that it applies to all associations. The option240* applies to each association's window size separately.241*242* <p> An implementation allows this socket option to be set before the243* socket is bound or connected. Whether an implementation allows the244* socket send buffer to be changed after the socket is bound is system245* dependent.246*/247public static final SctpSocketOption<Integer> SO_SNDBUF =248new SctpStdSocketOption<Integer>("SO_SNDBUF", Integer.class,249sun.nio.ch.sctp.SctpStdSocketOption.SO_SNDBUF);250251/**252* The size of the socket receive buffer.253*254* <P> The value of this socket option is an {@code Integer} that is the255* size of the socket receive buffer in bytes. The socket receive buffer is256* an input buffer used by the networking implementation. It may need to be257* increased for high-volume connections or decreased to limit the possible258* backlog of incoming data. The value of the socket option is a259* <em>hint</em> to the implementation to size the buffer and the actual260* size may differ.261*262* <P> For {@code SctpChannel}, this controls the receiver window size.263*264* <P> For {@code SctpMultiChannel}, the meaning is implementation265* dependent. It might control the receive buffer for each association bound266* to the socket descriptor or it might control the receive buffer for the267* whole socket.268*269* <p> An implementation allows this socket option to be set before the270* socket is bound or connected. Whether an implementation allows the271* socket receive buffer to be changed after the socket is bound is system272* dependent.273*/274public static final SctpSocketOption<Integer> SO_RCVBUF =275new SctpStdSocketOption<Integer>("SO_RCVBUF", Integer.class,276sun.nio.ch.sctp.SctpStdSocketOption.SO_RCVBUF);277278/**279* Linger on close if data is present.280*281* <p> The value of this socket option is an {@code Integer} that controls282* the action taken when unsent data is queued on the socket and a method283* to close the socket is invoked. If the value of the socket option is zero284* or greater, then it represents a timeout value, in seconds, known as the285* <em>linger interval</em>. The linger interval is the timeout for the286* {@code close} method to block while the operating system attempts to287* transmit the unsent data or it decides that it is unable to transmit the288* data. If the value of the socket option is less than zero then the option289* is disabled. In that case the {@code close} method does not wait until290* unsent data is transmitted; if possible the operating system will transmit291* any unsent data before the connection is closed.292*293* <p> This socket option is intended for use with sockets that are configured294* in {@link java.nio.channels.SelectableChannel#isBlocking() blocking} mode295* only. The behavior of the {@code close} method when this option is296* enabled on a non-blocking socket is not defined.297*298* <p> The initial value of this socket option is a negative value, meaning299* that the option is disabled. The option may be enabled, or the linger300* interval changed, at any time. The maximum value of the linger interval301* is system dependent. Setting the linger interval to a value that is302* greater than its maximum value causes the linger interval to be set to303* its maximum value.304*/305public static final SctpSocketOption<Integer> SO_LINGER =306new SctpStdSocketOption<Integer>("SO_LINGER", Integer.class,307sun.nio.ch.sctp.SctpStdSocketOption.SO_LINGER);308309/**310* This class is used to set the maximum number of inbound/outbound streams311* used by the local endpoint during association initialization. An312* instance of this class is used to set the {@link313* SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS SCTP_INIT_MAXSTREAMS}314* socket option.315*316* @since 1.7317*/318@jdk.Exported319public static class InitMaxStreams {320private int maxInStreams;321private int maxOutStreams;322323private InitMaxStreams(int maxInStreams, int maxOutStreams) {324this.maxInStreams = maxInStreams;325this.maxOutStreams = maxOutStreams;326}327328/**329* Creates an InitMaxStreams instance.330*331* @param maxInStreams332* The maximum number of inbound streams, where333* {@code 0 <= maxInStreams <= 65536}334*335* @param maxOutStreams336* The maximum number of outbound streams, where337* {@code 0 <= maxOutStreams <= 65536}338*339* @return An {@code InitMaxStreams} instance340*341* @throws IllegalArgumentException342* If an argument is outside of specified bounds343*/344public static InitMaxStreams create345(int maxInStreams, int maxOutStreams) {346if (maxOutStreams < 0 || maxOutStreams > 65535)347throw new IllegalArgumentException(348"Invalid maxOutStreams value");349if (maxInStreams < 0 || maxInStreams > 65535)350throw new IllegalArgumentException(351"Invalid maxInStreams value");352353return new InitMaxStreams(maxInStreams, maxOutStreams);354}355356/**357* Returns the maximum number of inbound streams.358*359* @return Maximum inbound streams360*/361public int maxInStreams() {362return maxInStreams;363}364365/**366* Returns the maximum number of outbound streams.367*368* @return Maximum outbound streams369*/370public int maxOutStreams() {371return maxOutStreams;372}373374/**375* Returns a string representation of this init max streams, including376* the maximum in and out bound streams.377*378* @return A string representation of this init max streams379*/380@Override381public String toString() {382StringBuilder sb = new StringBuilder();383sb.append(super.toString()).append(" [");384sb.append("maxInStreams:").append(maxInStreams);385sb.append("maxOutStreams:").append(maxOutStreams).append("]");386return sb.toString();387}388389/**390* Returns true if the specified object is another {@code InitMaxStreams}391* instance with the same number of in and out bound streams.392*393* @param obj394* The object to be compared with this init max streams395*396* @return true if the specified object is another397* {@code InitMaxStreams} instance with the same number of in398* and out bound streams399*/400@Override401public boolean equals(Object obj) {402if (obj != null && obj instanceof InitMaxStreams) {403InitMaxStreams that = (InitMaxStreams) obj;404if (this.maxInStreams == that.maxInStreams &&405this.maxOutStreams == that.maxOutStreams)406return true;407}408return false;409}410411/**412* Returns a hash code value for this init max streams.413*/414@Override415public int hashCode() {416int hash = 7 ^ maxInStreams ^ maxOutStreams;417return hash;418}419}420}421422423