Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/nio/sctp/SctpChannel.java
38924 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.ByteBuffer;31import java.nio.channels.spi.AbstractSelectableChannel;32import java.nio.channels.spi.SelectorProvider;33import java.nio.channels.ClosedChannelException;34import java.nio.channels.SelectionKey;3536/**37* A selectable channel for message-oriented connected SCTP sockets.38*39* <P> An SCTP channel can only control one SCTP association.40* An {@code SCTPChannel} is created by invoking one of the41* {@link #open open} methods of this class. A newly-created channel is open but42* not yet connected, that is, there is no association setup with a remote peer.43* An attempt to invoke an I/O operation upon an unconnected44* channel will cause a {@link java.nio.channels.NotYetConnectedException} to be45* thrown. An association can be setup by connecting the channel using one of46* its {@link #connect connect} methods. Once connected, the channel remains47* connected until it is closed. Whether or not a channel is connected may be48* determined by invoking {@link #getRemoteAddresses getRemoteAddresses}.49*50* <p> SCTP channels support <i>non-blocking connection:</i> A51* channel may be created and the process of establishing the link to52* the remote socket may be initiated via the {@link #connect connect} method53* for later completion by the {@link #finishConnect finishConnect} method.54* Whether or not a connection operation is in progress may be determined by55* invoking the {@link #isConnectionPending isConnectionPending} method.56*57* <p> Socket options are configured using the58* {@link #setOption(SctpSocketOption,Object) setOption} method. An SCTP59* channel support the following options:60* <blockquote>61* <table border summary="Socket options">62* <tr>63* <th>Option Name</th>64* <th>Description</th>65* </tr>66* <tr>67* <td> {@link SctpStandardSocketOptions#SCTP_DISABLE_FRAGMENTS68* SCTP_DISABLE_FRAGMENTS} </td>69* <td> Enables or disables message fragmentation </td>70* </tr>71* <tr>72* <td> {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE73* SCTP_EXPLICIT_COMPLETE} </td>74* <td> Enables or disables explicit message completion </td>75* </tr>76* <tr>77* <td> {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE78* SCTP_FRAGMENT_INTERLEAVE} </td>79* <td> Controls how the presentation of messages occur for the message80* receiver </td>81* </tr>82* <tr>83* <td> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS84* SCTP_INIT_MAXSTREAMS} </td>85* <td> The maximum number of streams requested by the local endpoint during86* association initialization </td>87* </tr>88* <tr>89* <td> {@link SctpStandardSocketOptions#SCTP_NODELAY SCTP_NODELAY} </td>90* <td> Enables or disable a Nagle-like algorithm </td>91* </tr>92* <tr>93* <td> {@link SctpStandardSocketOptions#SCTP_PRIMARY_ADDR94* SCTP_PRIMARY_ADDR} </td>95* <td> Requests that the local SCTP stack use the given peer address as the96* association primary </td>97* </tr>98* <tr>99* <td> {@link SctpStandardSocketOptions#SCTP_SET_PEER_PRIMARY_ADDR100* SCTP_SET_PEER_PRIMARY_ADDR} </td>101* <td> Requests that the peer mark the enclosed address as the association102* primary </td>103* </tr>104* <tr>105* <td> {@link SctpStandardSocketOptions#SO_SNDBUF106* SO_SNDBUF} </td>107* <td> The size of the socket send buffer </td>108* </tr>109* <tr>110* <td> {@link SctpStandardSocketOptions#SO_RCVBUF111* SO_RCVBUF} </td>112* <td> The size of the socket receive buffer </td>113* </tr>114* <tr>115* <td> {@link SctpStandardSocketOptions#SO_LINGER116* SO_LINGER} </td>117* <td> Linger on close if data is present (when configured in blocking mode118* only) </td>119* </tr>120* </table>121* </blockquote>122* Additional (implementation specific) options may also be supported. The list123* of options supported is obtained by invoking the {@link #supportedOptions()124* supportedOptions} method.125*126* <p> SCTP channels are safe for use by multiple concurrent threads.127* They support concurrent reading and writing, though at most one thread may be128* reading and at most one thread may be writing at any given time. The129* {@link #connect connect} and {@link #finishConnect130* finishConnect} methods are mutually synchronized against each other, and131* an attempt to initiate a send or receive operation while an invocation of one132* of these methods is in progress will block until that invocation is complete.133*134* @since 1.7135*/136@jdk.Exported137public abstract class SctpChannel138extends AbstractSelectableChannel139{140/**141* Initializes a new instance of this class.142*143* @param provider144* The selector provider for this channel145*/146protected SctpChannel(SelectorProvider provider) {147super(provider);148}149150/**151* Opens an SCTP channel.152*153* <P> The new channel is unbound and unconnected.154*155* @return A new SCTP channel156*157* @throws UnsupportedOperationException158* If the SCTP protocol is not supported159*160* @throws IOException161* If an I/O error occurs162*/163public static SctpChannel open() throws164IOException {165return new sun.nio.ch.sctp.SctpChannelImpl((SelectorProvider)null);166}167168/**169* Opens an SCTP channel and connects it to a remote address.170*171* <P> This is a convenience method and is equivalent to evaluating the172* following expression:173* <blockquote><pre>174* open().connect(remote, maxOutStreams, maxInStreams);175* </pre></blockquote>176*177* @param remote178* The remote address to which the new channel is to be connected179*180* @param maxOutStreams181* The number of streams that the application wishes to be able182* to send to. Must be non negative and no larger than {@code 65536}.183* {@code 0} to use the endpoints default value.184*185* @param maxInStreams186* The maximum number of inbound streams the application is prepared187* to support. Must be non negative and no larger than {@code 65536}.188* {@code 0} to use the endpoints default value.189*190* @return A new SCTP channel connected to the given address191*192* @throws java.nio.channels.AsynchronousCloseException193* If another thread closes this channel194* while the connect operation is in progress195*196* @throws java.nio.channels.ClosedByInterruptException197* If another thread interrupts the current thread198* while the connect operation is in progress, thereby199* closing the channel and setting the current thread's200* interrupt status201*202* @throws java.nio.channels.UnresolvedAddressException203* If the given remote address is not fully resolved204*205* @throws java.nio.channels.UnsupportedAddressTypeException206* If the type of the given remote address is not supported207*208* @throws SecurityException209* If a security manager has been installed210* and it does not permit access to the given remote peer211*212* @throws UnsupportedOperationException213* If the SCTP protocol is not supported214*215* @throws IOException216* If some other I/O error occurs217*/218public static SctpChannel open(SocketAddress remote, int maxOutStreams,219int maxInStreams) throws IOException {220SctpChannel ssc = SctpChannel.open();221ssc.connect(remote, maxOutStreams, maxInStreams);222return ssc;223}224225/**226* Returns the association on this channel's socket.227*228* @return the association, or {@code null} if the channel's socket is not229* connected.230*231* @throws ClosedChannelException232* If the channel is closed233*234* @throws IOException235* If some other I/O error occurs236*/237public abstract Association association() throws IOException;238239/**240* Binds the channel's socket to a local address.241*242* <P> This method is used to establish a relationship between the socket243* and the local addresses. Once a relationship is established then244* the socket remains bound until the channel is closed. This relationship245* may not necesssarily be with the address {@code local} as it may be removed246* by {@link #unbindAddress unbindAddress}, but there will always be at least247* one local address bound to the channel's socket once an invocation of248* this method successfully completes.249*250* <P> Once the channel's socket has been successfully bound to a specific251* address, that is not automatically assigned, more addresses252* may be bound to it using {@link #bindAddress bindAddress}, or removed253* using {@link #unbindAddress unbindAddress}.254*255* @param local256* The local address to bind the socket, or {@code null} to257* bind the socket to an automatically assigned socket address258*259* @return This channel260*261* @throws java.nio.channels.AlreadyConnectedException262* If this channel is already connected263*264* @throws java.nio.channels.ClosedChannelException265* If this channel is closed266*267* @throws java.nio.channels.ConnectionPendingException268* If a non-blocking connection operation is already in progress on this channel269*270* @throws java.nio.channels.AlreadyBoundException271* If this channel is already bound272*273* @throws java.nio.channels.UnsupportedAddressTypeException274* If the type of the given address is not supported275*276* @throws IOException277* If some other I/O error occurs278*279* @throws SecurityException280* If a security manager has been installed and its281* {@link SecurityManager#checkListen checkListen} method denies282* the operation283*/284public abstract SctpChannel bind(SocketAddress local)285throws IOException;286287/**288* Adds the given address to the bound addresses for the channel's289* socket.290*291* <P> The given address must not be the {@link292* java.net.InetAddress#isAnyLocalAddress wildcard} address.293* The channel must be first bound using {@link #bind bind} before294* invoking this method, otherwise {@link295* java.nio.channels.NotYetBoundException} is thrown. The {@link #bind bind}296* method takes a {@code SocketAddress} as its argument which typically297* contains a port number as well as an address. Addresses subquently bound298* using this method are simply addresses as the SCTP port number remains299* the same for the lifetime of the channel.300*301* <P> Adding addresses to a connected association is optional functionality.302* If the endpoint supports dynamic address reconfiguration then it may303* send the appropriate message to the peer to change the peers address304* lists.305*306* @param address307* The address to add to the bound addresses for the socket308*309* @return This channel310*311* @throws java.nio.channels.ClosedChannelException312* If this channel is closed313*314* @throws java.nio.channels.ConnectionPendingException315* If a non-blocking connection operation is already in progress on316* this channel317*318* @throws java.nio.channels.NotYetBoundException319* If this channel is not yet bound320*321* @throws java.nio.channels.AlreadyBoundException322* If this channel is already bound to the given address323*324* @throws IllegalArgumentException325* If address is {@code null} or the {@link326* java.net.InetAddress#isAnyLocalAddress wildcard} address327*328* @throws IOException329* If some other I/O error occurs330*/331public abstract SctpChannel bindAddress(InetAddress address)332throws IOException;333334/**335* Removes the given address from the bound addresses for the channel's336* socket.337*338* <P> The given address must not be the {@link339* java.net.InetAddress#isAnyLocalAddress wildcard} address.340* The channel must be first bound using {@link #bind bind} before341* invoking this method, otherwise {@link java.nio.channels.NotYetBoundException}342* is thrown. If this method is invoked on a channel that does not have343* {@code address} as one of its bound addresses or that has only one344* local address bound to it, then this method throws345* {@link IllegalUnbindException}.346* The initial address that the channel's socket is bound to using {@link347* #bind bind} may be removed from the bound addresses for the channel's socket.348*349* <P> Removing addresses from a connected association is optional350* functionality. If the endpoint supports dynamic address reconfiguration351* then it may send the appropriate message to the peer to change the peers352* address lists.353*354* @param address355* The address to remove from the bound addresses for the socket356*357* @return This channel358*359* @throws java.nio.channels.ClosedChannelException360* If this channel is closed361*362* @throws java.nio.channels.ConnectionPendingException363* If a non-blocking connection operation is already in progress on364* this channel365*366* @throws java.nio.channels.NotYetBoundException367* If this channel is not yet bound368*369* @throws IllegalArgumentException370* If address is {@code null} or the {@link371* java.net.InetAddress#isAnyLocalAddress wildcard} address372*373* @throws IllegalUnbindException374* If {@code address} is not bound to the channel's socket. or375* the channel has only one address bound to it376*377* @throws IOException378* If some other I/O error occurs379*/380public abstract SctpChannel unbindAddress(InetAddress address)381throws IOException;382383/**384* Connects this channel's socket.385*386* <P> If this channel is in non-blocking mode then an invocation of this387* method initiates a non-blocking connection operation. If the connection388* is established immediately, as can happen with a local connection, then389* this method returns {@code true}. Otherwise this method returns390* {@code false} and the connection operation must later be completed by391* invoking the {@link #finishConnect finishConnect} method.392*393* <P> If this channel is in blocking mode then an invocation of this394* method will block until the connection is established or an I/O error395* occurs.396*397* <P> If a security manager has been installed then this method verifies398* that its {@link java.lang.SecurityManager#checkConnect checkConnect}399* method permits connecting to the address and port number of the given400* remote peer.401*402* <p> This method may be invoked at any time. If a {@link #send send} or403* {@link #receive receive} operation upon this channel is invoked while an404* invocation of this method is in progress then that operation will first405* block until this invocation is complete. If a connection attempt is406* initiated but fails, that is, if an invocation of this method throws a407* checked exception, then the channel will be closed.408*409* @param remote410* The remote peer to which this channel is to be connected411*412* @return {@code true} if a connection was established, {@code false} if413* this channel is in non-blocking mode and the connection414* operation is in progress415*416* @throws java.nio.channels.AlreadyConnectedException417* If this channel is already connected418*419* @throws java.nio.channels.ConnectionPendingException420* If a non-blocking connection operation is already in progress on421* this channel422*423* @throws java.nio.channels.ClosedChannelException424* If this channel is closed425*426* @throws java.nio.channels.AsynchronousCloseException427* If another thread closes this channel428* while the connect operation is in progress429*430* @throws java.nio.channels.ClosedByInterruptException431* If another thread interrupts the current thread432* while the connect operation is in progress, thereby433* closing the channel and setting the current thread's434* interrupt status435*436* @throws java.nio.channels.UnresolvedAddressException437* If the given remote address is not fully resolved438*439* @throws java.nio.channels.UnsupportedAddressTypeException440* If the type of the given remote address is not supported441*442* @throws SecurityException443* If a security manager has been installed444* and it does not permit access to the given remote peer445*446* @throws IOException447* If some other I/O error occurs448*/449public abstract boolean connect(SocketAddress remote) throws IOException;450451/**452* Connects this channel's socket.453*454* <P> This is a convience method and is equivalent to evaluating the455* following expression:456* <blockquote><pre>457* setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, SctpStandardSocketOption.InitMaxStreams.create(maxInStreams, maxOutStreams))458* .connect(remote);459* </pre></blockquote>460*461* <P> The {@code maxOutStreams} and {@code maxInStreams} parameters462* represent the maximum number of streams that the application wishes to be463* able to send to and receive from. They are negotiated with the remote464* peer and may be limited by the operating system.465*466* @param remote467* The remote peer to which this channel is to be connected468*469* @param maxOutStreams470* Must be non negative and no larger than {@code 65536}.471* {@code 0} to use the endpoints default value.472*473* @param maxInStreams474* Must be non negative and no larger than {@code 65536}.475* {@code 0} to use the endpoints default value.476*477* @return {@code true} if a connection was established, {@code false} if478* this channel is in non-blocking mode and the connection operation479* is in progress480*481* @throws java.nio.channels.AlreadyConnectedException482* If this channel is already connected483*484* @throws java.nio.channels.ConnectionPendingException485* If a non-blocking connection operation is already in progress on486* this channel487*488* @throws java.nio.channels.ClosedChannelException489* If this channel is closed490*491* @throws java.nio.channels.AsynchronousCloseException492* If another thread closes this channel493* while the connect operation is in progress494*495* @throws java.nio.channels.ClosedByInterruptException496* If another thread interrupts the current thread497* while the connect operation is in progress, thereby498* closing the channel and setting the current thread's499* interrupt status500*501* @throws java.nio.channels.UnresolvedAddressException502* If the given remote address is not fully resolved503*504* @throws java.nio.channels.UnsupportedAddressTypeException505* If the type of the given remote address is not supported506*507* @throws SecurityException508* If a security manager has been installed509* and it does not permit access to the given remote peer510*511* @throws IOException512* If some other I/O error occurs513*/514public abstract boolean connect(SocketAddress remote,515int maxOutStreams,516int maxInStreams)517throws IOException;518519/**520* Tells whether or not a connection operation is in progress on this channel.521*522* @return {@code true} if, and only if, a connection operation has been initiated523* on this channel but not yet completed by invoking the524* {@link #finishConnect} method525*/526public abstract boolean isConnectionPending();527528/**529* Finishes the process of connecting an SCTP channel.530*531* <P> A non-blocking connection operation is initiated by placing a socket532* channel in non-blocking mode and then invoking one of its {@link #connect533* connect} methods. Once the connection is established, or the attempt has534* failed, the channel will become connectable and this method may535* be invoked to complete the connection sequence. If the connection536* operation failed then invoking this method will cause an appropriate537* {@link java.io.IOException} to be thrown.538*539* <P> If this channel is already connected then this method will not block540* and will immediately return <tt>true</tt>. If this channel is in541* non-blocking mode then this method will return <tt>false</tt> if the542* connection process is not yet complete. If this channel is in blocking543* mode then this method will block until the connection either completes544* or fails, and will always either return <tt>true</tt> or throw a checked545* exception describing the failure.546*547* <P> This method may be invoked at any time. If a {@link #send send} or {@link #receive receive}548* operation upon this channel is invoked while an invocation of this549* method is in progress then that operation will first block until this550* invocation is complete. If a connection attempt fails, that is, if an551* invocation of this method throws a checked exception, then the channel552* will be closed.553*554* @return {@code true} if, and only if, this channel's socket is now555* connected556*557* @throws java.nio.channels.NoConnectionPendingException558* If this channel is not connected and a connection operation559* has not been initiated560*561* @throws java.nio.channels.ClosedChannelException562* If this channel is closed563*564* @throws java.nio.channels.AsynchronousCloseException565* If another thread closes this channel566* while the connect operation is in progress567*568* @throws java.nio.channels.ClosedByInterruptException569* If another thread interrupts the current thread570* while the connect operation is in progress, thereby571* closing the channel and setting the current thread's572* interrupt status573*574* @throws IOException575* If some other I/O error occurs576*/577public abstract boolean finishConnect() throws IOException;578579/**580* Returns all of the socket addresses to which this channel's socket is581* bound.582*583* @return All the socket addresses that this channel's socket is584* bound to, or an empty {@code Set} if the channel's socket is not585* bound586*587* @throws ClosedChannelException588* If the channel is closed589*590* @throws IOException591* If an I/O error occurs592*/593public abstract Set<SocketAddress> getAllLocalAddresses()594throws IOException;595596/**597* Returns all of the remote addresses to which this channel's socket598* is connected.599*600* <P> If the channel is connected to a remote peer that is bound to601* multiple addresses then it is these addresses that the channel's socket602* is connected.603*604* @return All of the remote addresses to which this channel's socket605* is connected, or an empty {@code Set} if the channel's socket is606* not connected607*608* @throws ClosedChannelException609* If the channel is closed610*611* @throws IOException612* If an I/O error occurs613*/614public abstract Set<SocketAddress> getRemoteAddresses()615throws IOException;616617/**618* Shutdown a connection without closing the channel.619*620* <P> Sends a shutdown command to the remote peer, effectively preventing621* any new data from being written to the socket by either peer. Further622* sends will throw {@link java.nio.channels.ClosedChannelException}. The623* channel remains open to allow the for any data (and notifications) to be624* received that may have been sent by the peer before it received the625* shutdown command. If the channel is already shutdown then invoking this626* method has no effect.627*628* @return This channel629*630* @throws java.nio.channels.NotYetConnectedException631* If this channel is not yet connected632*633* @throws java.nio.channels.ClosedChannelException634* If this channel is closed635*636* @throws IOException637* If some other I/O error occurs638*/639public abstract SctpChannel shutdown() throws IOException;640641/**642* Returns the value of a socket option.643*644* @param <T>645* The type of the socket option value646*647* @param name648* The socket option649*650* @return The value of the socket option. A value of {@code null} may be651* a valid value for some socket options.652*653* @throws UnsupportedOperationException654* If the socket option is not supported by this channel655*656* @throws ClosedChannelException657* If this channel is closed658*659* @throws IOException660* If an I/O error occurs661*662* @see SctpStandardSocketOptions663*/664public abstract <T> T getOption(SctpSocketOption<T> name)665throws IOException;666667/**668* Sets the value of a socket option.669*670* @param <T>671* The type of the socket option value672*673* @param name674* The socket option675*676* @param value677* The value of the socket option. A value of {@code null} may be678* a valid value for some socket options.679*680* @return This channel681*682* @throws UnsupportedOperationException683* If the socket option is not supported by this channel684*685* @throws IllegalArgumentException686* If the value is not a valid value for this socket option687*688* @throws ClosedChannelException689* If this channel is closed690*691* @throws IOException692* If an I/O error occurs693*694* @see SctpStandardSocketOptions695*/696public abstract <T> SctpChannel setOption(SctpSocketOption<T> name, T value)697throws IOException;698699/**700* Returns a set of the socket options supported by this channel.701*702* <P> This method will continue to return the set of options even after the703* channel has been closed.704*705* @return A set of the socket options supported by this channel706*/707public abstract Set<SctpSocketOption<?>> supportedOptions();708709/**710* Returns an operation set identifying this channel's supported operations.711*712* <P> SCTP channels support connecting, reading, and writing, so this713* method returns <tt>(</tt>{@link SelectionKey#OP_CONNECT}714* <tt>|</tt> {@link SelectionKey#OP_READ} <tt>|</tt> {@link715* SelectionKey#OP_WRITE}<tt>)</tt>. </p>716*717* @return The valid-operation set718*/719@Override720public final int validOps() {721return (SelectionKey.OP_READ |722SelectionKey.OP_WRITE |723SelectionKey.OP_CONNECT);724}725726/**727* Receives a message into the given buffer and/or handles a notification.728*729* <P> If a message or notification is immediately available, or if this730* channel is in blocking mode and one eventually becomes available, then731* the message or notification is returned or handled, respectively. If this732* channel is in non-blocking mode and a message or notification is not733* immediately available then this method immediately returns {@code null}.734*735* <P> If this method receives a message it is copied into the given byte736* buffer. The message is transferred into the given byte buffer starting at737* its current position and the buffers position is incremented by the738* number of bytes read. If there are fewer bytes remaining in the buffer739* than are required to hold the message, or the underlying input buffer740* does not contain the complete message, then an invocation of {@link741* MessageInfo#isComplete isComplete} on the returned {@code742* MessageInfo} will return {@code false}, and more invocations of this743* method will be necessary to completely consume the messgae. Only744* one message at a time will be partially delivered in any stream. The745* socket option {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE746* SCTP_FRAGMENT_INTERLEAVE} controls various aspects of what interlacing of747* messages occurs.748*749* <P> If this method receives a notification then the appropriate method of750* the given handler, if there is one, is invoked. If the handler returns751* {@link HandlerResult#CONTINUE CONTINUE} then this method will try to752* receive another message/notification, otherwise, if {@link753* HandlerResult#RETURN RETURN} is returned this method will return {@code754* null}. If an uncaught exception is thrown by the handler it will be755* propagated up the stack through this method.756*757* <P> This method may be invoked at any time. If another thread has758* already initiated a receive operation upon this channel, then an759* invocation of this method will block until the first operation is760* complete. The given handler is invoked without holding any locks used761* to enforce the above synchronization policy, that way handlers762* will not stall other threads from receiving. A handler should not invoke763* the {@code receive} method of this channel, if it does an764* {@link IllegalReceiveException} will be thrown.765*766* @param <T>767* The type of the attachment768*769* @param dst770* The buffer into which message bytes are to be transferred771*772* @param attachment773* The object to attach to the receive operation; can be774* {@code null}775*776* @param handler777* A handler to handle notifications from the SCTP stack, or {@code778* null} to ignore any notifications.779*780* @return The {@code MessageInfo}, {@code null} if this channel is in781* non-blocking mode and no messages are immediately available or782* the notification handler returns {@link HandlerResult#RETURN783* RETURN} after handling a notification784*785* @throws java.nio.channels.ClosedChannelException786* If this channel is closed787*788* @throws java.nio.channels.AsynchronousCloseException789* If another thread closes this channel790* while the read operation is in progress791*792* @throws java.nio.channels.ClosedByInterruptException793* If another thread interrupts the current thread794* while the read operation is in progress, thereby795* closing the channel and setting the current thread's796* interrupt status797*798* @throws java.nio.channels.NotYetConnectedException799* If this channel is not yet connected800*801* @throws IllegalReceiveException802* If the given handler invokes the {@code receive} method of this803* channel804*805* @throws IOException806* If some other I/O error occurs807*/808public abstract <T> MessageInfo receive(ByteBuffer dst,809T attachment,810NotificationHandler<T> handler)811throws IOException;812813/**814* Sends a message via this channel.815*816* <P> If this channel is in non-blocking mode and there is sufficient room817* in the underlying output buffer, or if this channel is in blocking mode818* and sufficient room becomes available, then the remaining bytes in the819* given byte buffer are transmitted as a single message. Sending a message820* is atomic unless explicit message completion {@link821* SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE SCTP_EXPLICIT_COMPLETE}822* socket option is enabled on this channel's socket.823*824* <P> The message is transferred from the byte buffer as if by a regular825* {@link java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)826* write} operation.827*828* <P> The bytes will be written to the stream number that is specified by829* {@link MessageInfo#streamNumber streamNumber} in the given {@code830* messageInfo}.831*832* <P> This method may be invoked at any time. If another thread has already833* initiated a send operation upon this channel, then an invocation of834* this method will block until the first operation is complete.835*836* @param src837* The buffer containing the message to be sent838*839* @param messageInfo840* Ancillary data about the message to be sent841*842* @return The number of bytes sent, which will be either the number of843* bytes that were remaining in the messages buffer when this method844* was invoked or, if this channel is non-blocking, may be zero if845* there was insufficient room for the message in the underlying846* output buffer847*848* @throws InvalidStreamException849* If {@code streamNumner} is negative or greater than or equal to850* the maximum number of outgoing streams851*852* @throws java.nio.channels.ClosedChannelException853* If this channel is closed854*855* @throws java.nio.channels.AsynchronousCloseException856* If another thread closes this channel857* while the read operation is in progress858*859* @throws java.nio.channels.ClosedByInterruptException860* If another thread interrupts the current thread861* while the read operation is in progress, thereby862* closing the channel and setting the current thread's863* interrupt status864*865* @throws java.nio.channels.NotYetConnectedException866* If this channel is not yet connected867*868* @throws IOException869* If some other I/O error occurs870*/871public abstract int send(ByteBuffer src, MessageInfo messageInfo)872throws IOException;873}874875876