Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/nio/sctp/SctpServerChannel.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 java.net.InetAddress;28import java.io.IOException;29import java.util.Set;30import java.nio.channels.SelectionKey;31import java.nio.channels.spi.SelectorProvider;32import java.nio.channels.spi.AbstractSelectableChannel;3334/**35* A selectable channel for message-oriented listening SCTP sockets.36*37* <p> An {@code SCTPServerChannel} is created by invoking the38* {@link #open open} method of this class. A newly-created SCTP server39* channel is open but not yet bound. An attempt to invoke the40* {@link #accept accept} method of an unbound channel will cause the41* {@link java.nio.channels.NotYetBoundException} to be thrown. An SCTP server42* channel can be bound by invoking one of the43* {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class.44*45* <p> Socket options are configured using the46* {@link #setOption(SctpSocketOption,Object) setOption} method. SCTP server socket47* channels support the following options:48* <blockquote>49* <table border summary="Socket options">50* <tr>51* <th>Option Name</th>52* <th>Description</th>53* </tr>54* <tr>55* <td> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS56* SCTP_INIT_MAXSTREAMS} </td>57* <td> The maximum number of streams requested by the local endpoint during58* association initialization </td>59* </tr>60* </table>61* </blockquote>62* Additional (implementation specific) options may also be supported. The list63* of options supported is obtained by invoking the {@link #supportedOptions()64* supportedOptions} method.65*66* <p>SCTP server channels are safe for use by multiple concurrent threads.67*68* @since 1.769*/70@jdk.Exported71public abstract class SctpServerChannel72extends AbstractSelectableChannel73{74/**75* Initializes a new instance of this class.76*77* @param provider78* The selector provider for this channel79*/80protected SctpServerChannel(SelectorProvider provider) {81super(provider);82}8384/**85* Opens an SCTP server channel.86*87* <P> The new channel's socket is initially unbound; it must be bound88* to a specific address via one of its socket's {@link #bind bind}89* methods before associations can be accepted.90*91* @return A new SCTP server channel92*93* @throws UnsupportedOperationException94* If the SCTP protocol is not supported95*96* @throws IOException97* If an I/O error occurs98*/99public static SctpServerChannel open() throws100IOException {101return new sun.nio.ch.sctp.SctpServerChannelImpl((SelectorProvider)null);102}103104/**105* Accepts an association on this channel's socket.106*107* <P> If this channel is in non-blocking mode then this method will108* immediately return {@code null} if there are no pending associations.109* Otherwise it will block indefinitely until a new association is110* available or an I/O error occurs.111*112* <P> The {@code SCTPChannel} returned by this method, if any, will be in113* blocking mode regardless of the blocking mode of this channel.114*115* <P> If a security manager has been installed then for each new116* association this method verifies that the address and port number of the117* assocaitions's remote peer are permitted by the security manager's {@link118* java.lang.SecurityManager#checkAccept(String,int) checkAccept} method.119*120* @return The SCTP channel for the new association, or {@code null}121* if this channel is in non-blocking mode and no association is122* available to be accepted123*124* @throws java.nio.channels.ClosedChannelException125* If this channel is closed126*127* @throws java.nio.channels.AsynchronousCloseException128* If another thread closes this channel129* while the accept operation is in progress130*131* @throws java.nio.channels.ClosedByInterruptException132* If another thread interrupts the current thread133* while the accept operation is in progress, thereby134* closing the channel and setting the current thread's135* interrupt status136*137* @throws java.nio.channels.NotYetBoundException138* If this channel's socket has not yet been bound139*140* @throws SecurityException141* If a security manager has been installed and it does not permit142* access to the remote peer of the new association143*144* @throws IOException145* If some other I/O error occurs146*/147public abstract SctpChannel accept() throws IOException;148149/**150* Binds the channel's socket to a local address and configures the socket151* to listen for associations.152*153* <P> This method works as if invoking it were equivalent to evaluating the154* expression:155* <blockquote><pre>156* bind(local, 0);157* </pre></blockquote>158*159* @param local160* The local address to bind the socket, or {@code null} to161* bind the socket to an automatically assigned socket address162*163* @return This channel164*165* @throws java.nio.channels.ClosedChannelException166* If this channel is closed167*168* @throws java.nio.channels.AlreadyBoundException169* If this channel is already bound170*171* @throws java.nio.channels.UnsupportedAddressTypeException172* If the type of the given address is not supported173*174* @throws SecurityException175* If a security manager has been installed and its {@link176* java.lang.SecurityManager#checkListen(int) checkListen} method177* denies the operation178*179* @throws IOException180* If some other I/O error occurs181*/182public final SctpServerChannel bind(SocketAddress local)183throws IOException {184return bind(local, 0);185}186187/**188* Binds the channel's socket to a local address and configures the socket189* to listen for associations.190*191* <P> This method is used to establish a relationship between the socket192* and the local address. Once a relationship is established then193* the socket remains bound until the channel is closed. This relationship194* may not necesssarily be with the address {@code local} as it may be195* removed by {@link #unbindAddress unbindAddress}, but there will always be196* at least one local address bound to the channel's socket once an197* invocation of this method successfully completes.198*199* <P> Once the channel's socket has been successfully bound to a specific200* address, that is not automatically assigned, more addresses201* may be bound to it using {@link #bindAddress bindAddress}, or removed202* using {@link #unbindAddress unbindAddress}.203*204* <P> The backlog parameter is the maximum number of pending associations205* on the socket. Its exact semantics are implementation specific. An206* implementation may impose an implementation specific maximum length or207* may choose to ignore the parameter. If the backlog parameter has the208* value {@code 0}, or a negative value, then an implementation specific209* default is used.210*211* @param local212* The local address to bind the socket, or {@code null} to213* bind the socket to an automatically assigned socket address214*215* @param backlog216* The maximum number number of pending associations217*218* @return This channel219*220* @throws java.nio.channels.ClosedChannelException221* If this channel is closed222*223* @throws java.nio.channels.AlreadyBoundException224* If this channel is already bound225*226* @throws java.nio.channels.UnsupportedAddressTypeException227* If the type of the given address is not supported228*229* @throws SecurityException230* If a security manager has been installed and its {@link231* java.lang.SecurityManager#checkListen(int) checkListen} method232* denies the operation233*234* @throws IOException235* If some other I/O error occurs236*/237public abstract SctpServerChannel bind(SocketAddress local,238int backlog)239throws IOException;240241/**242* Adds the given address to the bound addresses for the channel's243* socket.244*245* <P> The given address must not be the {@link246* java.net.InetAddress#isAnyLocalAddress wildcard} address.247* The channel must be first bound using {@link #bind bind} before248* invoking this method, otherwise {@link249* java.nio.channels.NotYetBoundException} is thrown. The {@link #bind bind}250* method takes a {@code SocketAddress} as its argument which typically251* contains a port number as well as an address. Addresses subquently bound252* using this method are simply addresses as the SCTP port number remains253* the same for the lifetime of the channel.254*255* <P> New associations accepted after this method successfully completes256* will be associated with the given address.257*258* @param address259* The address to add to the bound addresses for the socket260*261* @return This channel262*263* @throws java.nio.channels.ClosedChannelException264* If this channel is closed265*266* @throws java.nio.channels.NotYetBoundException267* If this channel is not yet bound268*269* @throws java.nio.channels.AlreadyBoundException270* If this channel is already bound to the given address271*272* @throws IllegalArgumentException273* If address is {@code null} or the {@link274* java.net.InetAddress#isAnyLocalAddress wildcard} address275*276* @throws IOException277* If some other I/O error occurs278*/279public abstract SctpServerChannel bindAddress(InetAddress address)280throws IOException;281282/**283* Removes the given address from the bound addresses for the channel's284* socket.285*286* <P> The given address must not be the {@link287* java.net.InetAddress#isAnyLocalAddress wildcard} address.288* The channel must be first bound using {@link #bind bind} before289* invoking this method, otherwise290* {@link java.nio.channels.NotYetBoundException} is thrown.291* If this method is invoked on a channel that does not have292* {@code address} as one of its bound addresses, or that has only one293* local address bound to it, then this method throws {@link294* IllegalUnbindException}.295* The initial address that the channel's socket is bound to using296* {@link #bind bind} may be removed from the bound addresses for the297* channel's socket.298*299* <P> New associations accepted after this method successfully completes300* will not be associated with the given address.301*302* @param address303* The address to remove from the bound addresses for the socket304*305* @return This channel306*307* @throws java.nio.channels.ClosedChannelException308* If this channel is closed309*310* @throws java.nio.channels.NotYetBoundException311* If this channel is not yet bound312*313* @throws IllegalArgumentException314* If address is {@code null} or the {@link315* java.net.InetAddress#isAnyLocalAddress wildcard} address316*317* @throws IllegalUnbindException318* If the implementation does not support removing addresses from a319* listening socket, {@code address} is not bound to the channel's320* socket, or the channel has only one address bound to it321*322* @throws IOException323* If some other I/O error occurs324*/325public abstract SctpServerChannel unbindAddress(InetAddress address)326throws IOException;327328/**329* Returns all of the socket addresses to which this channel's socket is330* bound.331*332* @return All the socket addresses that this channel's socket is333* bound to, or an empty {@code Set} if the channel's socket is not334* bound335*336* @throws java.nio.channels.ClosedChannelException337* If the channel is closed338*339* @throws IOException340* If an I/O error occurs341*/342public abstract Set<SocketAddress> getAllLocalAddresses()343throws IOException;344345/**346* Returns the value of a socket option.347*348* @param <T>349* The type of the socket option value350*351* @param name352* The socket option353*354* @return The value of the socket option. A value of {@code null} may be355* a valid value for some socket options.356*357* @throws UnsupportedOperationException358* If the socket option is not supported by this channel359*360* @throws java.nio.channels.ClosedChannelException361* If this channel is closed362*363* @throws IOException364* If an I/O error occurs365*366* @see SctpStandardSocketOptions367*/368public abstract <T> T getOption(SctpSocketOption<T> name) throws IOException;369370/**371* Sets the value of a socket option.372*373* @param <T>374* The type of the socket option value375*376* @param name377* The socket option378*379* @param value380* The value of the socket option. A value of {@code null} may be381* a valid value for some socket options.382*383* @return This channel384*385* @throws UnsupportedOperationException386* If the socket option is not supported by this channel387*388* @throws IllegalArgumentException389* If the value is not a valid value for this socket option390*391* @throws java.nio.channels.ClosedChannelException392* If this channel is closed393*394* @throws IOException395* If an I/O error occurs396*397* @see SctpStandardSocketOptions398*/399public abstract <T> SctpServerChannel setOption(SctpSocketOption<T> name,400T value)401throws IOException;402403/**404* Returns a set of the socket options supported by this channel.405*406* <P> This method will continue to return the set of options even after the407* channel has been closed.408*409* @return A set of the socket options supported by this channel410*/411public abstract Set<SctpSocketOption<?>> supportedOptions();412413/**414* Returns an operation set identifying this channel's supported415* operations.416*417* <P> SCTP server channels only support the accepting of new418* associations, so this method returns419* {@link java.nio.channels.SelectionKey#OP_ACCEPT}.420*421* @return The valid-operation set422*/423@Override424public final int validOps() {425return SelectionKey.OP_ACCEPT;426}427}428429430