author | joehw |
Tue, 07 Nov 2017 16:19:55 -0800 | |
changeset 47712 | bde0215f1f70 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
45132
db2f2d72cd4f
8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents:
34894
diff
changeset
|
2 |
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. |
2542 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2542 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2542 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2542 | 24 |
*/ |
25 |
package com.sun.nio.sctp; |
|
26 |
||
27 |
import java.net.SocketAddress; |
|
28 |
import java.net.InetAddress; |
|
29 |
import java.io.IOException; |
|
30 |
import java.util.Set; |
|
31 |
import java.nio.ByteBuffer; |
|
32 |
import java.nio.channels.spi.AbstractSelectableChannel; |
|
33 |
import java.nio.channels.spi.SelectorProvider; |
|
34 |
import java.nio.channels.ClosedChannelException; |
|
35 |
import java.nio.channels.SelectionKey; |
|
36 |
||
37 |
/** |
|
38 |
* A selectable channel for message-oriented connected SCTP sockets. |
|
39 |
* |
|
40 |
* <P> An SCTP channel can only control one SCTP association. |
|
41 |
* An {@code SCTPChannel} is created by invoking one of the |
|
42 |
* {@link #open open} methods of this class. A newly-created channel is open but |
|
43 |
* not yet connected, that is, there is no association setup with a remote peer. |
|
44 |
* An attempt to invoke an I/O operation upon an unconnected |
|
45 |
* channel will cause a {@link java.nio.channels.NotYetConnectedException} to be |
|
46 |
* thrown. An association can be setup by connecting the channel using one of |
|
47 |
* its {@link #connect connect} methods. Once connected, the channel remains |
|
48 |
* connected until it is closed. Whether or not a channel is connected may be |
|
49 |
* determined by invoking {@link #getRemoteAddresses getRemoteAddresses}. |
|
50 |
* |
|
51 |
* <p> SCTP channels support <i>non-blocking connection:</i> A |
|
52 |
* channel may be created and the process of establishing the link to |
|
53 |
* the remote socket may be initiated via the {@link #connect connect} method |
|
54 |
* for later completion by the {@link #finishConnect finishConnect} method. |
|
55 |
* Whether or not a connection operation is in progress may be determined by |
|
56 |
* invoking the {@link #isConnectionPending isConnectionPending} method. |
|
57 |
* |
|
58 |
* <p> Socket options are configured using the |
|
59 |
* {@link #setOption(SctpSocketOption,Object) setOption} method. An SCTP |
|
60 |
* channel support the following options: |
|
61 |
* <blockquote> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
62 |
* <table class="striped"> |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
63 |
* <caption style="display:none">Socket options</caption> |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
64 |
* <thead> |
2542 | 65 |
* <tr> |
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
66 |
* <th scope="col">Option Name</th> |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
67 |
* <th scope="col">Description</th> |
2542 | 68 |
* </tr> |
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
69 |
* </thead> |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
70 |
* <tbody> |
2542 | 71 |
* <tr> |
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
72 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_DISABLE_FRAGMENTS |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
73 |
* SCTP_DISABLE_FRAGMENTS} </th> |
2542 | 74 |
* <td> Enables or disables message fragmentation </td> |
75 |
* </tr> |
|
76 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
77 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
78 |
* SCTP_EXPLICIT_COMPLETE} </th> |
2542 | 79 |
* <td> Enables or disables explicit message completion </td> |
80 |
* </tr> |
|
81 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
82 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
83 |
* SCTP_FRAGMENT_INTERLEAVE} </th> |
2542 | 84 |
* <td> Controls how the presentation of messages occur for the message |
85 |
* receiver </td> |
|
86 |
* </tr> |
|
87 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
88 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
89 |
* SCTP_INIT_MAXSTREAMS} </th> |
2542 | 90 |
* <td> The maximum number of streams requested by the local endpoint during |
91 |
* association initialization </td> |
|
92 |
* </tr> |
|
93 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
94 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_NODELAY SCTP_NODELAY} </th> |
2542 | 95 |
* <td> Enables or disable a Nagle-like algorithm </td> |
96 |
* </tr> |
|
97 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
98 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_PRIMARY_ADDR |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
99 |
* SCTP_PRIMARY_ADDR} </th> |
2542 | 100 |
* <td> Requests that the local SCTP stack use the given peer address as the |
101 |
* association primary </td> |
|
102 |
* </tr> |
|
103 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
104 |
* <th scope="row"> {@link SctpStandardSocketOptions#SCTP_SET_PEER_PRIMARY_ADDR |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
105 |
* SCTP_SET_PEER_PRIMARY_ADDR} </th> |
2542 | 106 |
* <td> Requests that the peer mark the enclosed address as the association |
107 |
* primary </td> |
|
108 |
* </tr> |
|
109 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
110 |
* <th scope="row"> {@link SctpStandardSocketOptions#SO_SNDBUF |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
111 |
* SO_SNDBUF} </th> |
2542 | 112 |
* <td> The size of the socket send buffer </td> |
113 |
* </tr> |
|
114 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
115 |
* <th scope="row"> {@link SctpStandardSocketOptions#SO_RCVBUF |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
116 |
* SO_RCVBUF} </th> |
2542 | 117 |
* <td> The size of the socket receive buffer </td> |
118 |
* </tr> |
|
119 |
* <tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
120 |
* <th scope="row"> {@link SctpStandardSocketOptions#SO_LINGER |
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
121 |
* SO_LINGER} </th> |
2542 | 122 |
* <td> Linger on close if data is present (when configured in blocking mode |
123 |
* only) </td> |
|
124 |
* </tr> |
|
45882
341b124f1001
8184304: (sctp) make tables in jdk.sctp module accessible
jjg
parents:
45132
diff
changeset
|
125 |
* </tbody> |
2542 | 126 |
* </table> |
127 |
* </blockquote> |
|
128 |
* Additional (implementation specific) options may also be supported. The list |
|
129 |
* of options supported is obtained by invoking the {@link #supportedOptions() |
|
130 |
* supportedOptions} method. |
|
131 |
* |
|
132 |
* <p> SCTP channels are safe for use by multiple concurrent threads. |
|
133 |
* They support concurrent reading and writing, though at most one thread may be |
|
134 |
* reading and at most one thread may be writing at any given time. The |
|
135 |
* {@link #connect connect} and {@link #finishConnect |
|
136 |
* finishConnect} methods are mutually synchronized against each other, and |
|
137 |
* an attempt to initiate a send or receive operation while an invocation of one |
|
138 |
* of these methods is in progress will block until that invocation is complete. |
|
139 |
* |
|
140 |
* @since 1.7 |
|
141 |
*/ |
|
142 |
public abstract class SctpChannel |
|
143 |
extends AbstractSelectableChannel |
|
144 |
{ |
|
145 |
/** |
|
146 |
* Initializes a new instance of this class. |
|
147 |
* |
|
148 |
* @param provider |
|
149 |
* The selector provider for this channel |
|
150 |
*/ |
|
151 |
protected SctpChannel(SelectorProvider provider) { |
|
152 |
super(provider); |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* Opens an SCTP channel. |
|
157 |
* |
|
158 |
* <P> The new channel is unbound and unconnected. |
|
159 |
* |
|
160 |
* @return A new SCTP channel |
|
161 |
* |
|
162 |
* @throws UnsupportedOperationException |
|
163 |
* If the SCTP protocol is not supported |
|
164 |
* |
|
165 |
* @throws IOException |
|
166 |
* If an I/O error occurs |
|
167 |
*/ |
|
168 |
public static SctpChannel open() throws |
|
169 |
IOException { |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
9679
diff
changeset
|
170 |
return new sun.nio.ch.sctp.SctpChannelImpl((SelectorProvider)null); |
2542 | 171 |
} |
172 |
||
173 |
/** |
|
174 |
* Opens an SCTP channel and connects it to a remote address. |
|
175 |
* |
|
176 |
* <P> This is a convenience method and is equivalent to evaluating the |
|
177 |
* following expression: |
|
178 |
* <blockquote><pre> |
|
179 |
* open().connect(remote, maxOutStreams, maxInStreams); |
|
180 |
* </pre></blockquote> |
|
181 |
* |
|
182 |
* @param remote |
|
183 |
* The remote address to which the new channel is to be connected |
|
184 |
* |
|
185 |
* @param maxOutStreams |
|
186 |
* The number of streams that the application wishes to be able |
|
187 |
* to send to. Must be non negative and no larger than {@code 65536}. |
|
188 |
* {@code 0} to use the endpoints default value. |
|
189 |
* |
|
190 |
* @param maxInStreams |
|
191 |
* The maximum number of inbound streams the application is prepared |
|
192 |
* to support. Must be non negative and no larger than {@code 65536}. |
|
193 |
* {@code 0} to use the endpoints default value. |
|
194 |
* |
|
195 |
* @return A new SCTP channel connected to the given address |
|
196 |
* |
|
197 |
* @throws java.nio.channels.AsynchronousCloseException |
|
198 |
* If another thread closes this channel |
|
199 |
* while the connect operation is in progress |
|
200 |
* |
|
201 |
* @throws java.nio.channels.ClosedByInterruptException |
|
202 |
* If another thread interrupts the current thread |
|
203 |
* while the connect operation is in progress, thereby |
|
204 |
* closing the channel and setting the current thread's |
|
205 |
* interrupt status |
|
206 |
* |
|
207 |
* @throws java.nio.channels.UnresolvedAddressException |
|
208 |
* If the given remote address is not fully resolved |
|
209 |
* |
|
210 |
* @throws java.nio.channels.UnsupportedAddressTypeException |
|
211 |
* If the type of the given remote address is not supported |
|
212 |
* |
|
213 |
* @throws SecurityException |
|
214 |
* If a security manager has been installed |
|
215 |
* and it does not permit access to the given remote peer |
|
216 |
* |
|
217 |
* @throws UnsupportedOperationException |
|
218 |
* If the SCTP protocol is not supported |
|
219 |
* |
|
220 |
* @throws IOException |
|
221 |
* If some other I/O error occurs |
|
222 |
*/ |
|
223 |
public static SctpChannel open(SocketAddress remote, int maxOutStreams, |
|
224 |
int maxInStreams) throws IOException { |
|
225 |
SctpChannel ssc = SctpChannel.open(); |
|
226 |
ssc.connect(remote, maxOutStreams, maxInStreams); |
|
227 |
return ssc; |
|
228 |
} |
|
229 |
||
230 |
/** |
|
231 |
* Returns the association on this channel's socket. |
|
232 |
* |
|
233 |
* @return the association, or {@code null} if the channel's socket is not |
|
234 |
* connected. |
|
235 |
* |
|
236 |
* @throws ClosedChannelException |
|
237 |
* If the channel is closed |
|
238 |
* |
|
239 |
* @throws IOException |
|
240 |
* If some other I/O error occurs |
|
241 |
*/ |
|
242 |
public abstract Association association() throws IOException; |
|
243 |
||
244 |
/** |
|
245 |
* Binds the channel's socket to a local address. |
|
246 |
* |
|
247 |
* <P> This method is used to establish a relationship between the socket |
|
248 |
* and the local addresses. Once a relationship is established then |
|
249 |
* the socket remains bound until the channel is closed. This relationship |
|
250 |
* may not necesssarily be with the address {@code local} as it may be removed |
|
251 |
* by {@link #unbindAddress unbindAddress}, but there will always be at least |
|
252 |
* one local address bound to the channel's socket once an invocation of |
|
253 |
* this method successfully completes. |
|
254 |
* |
|
255 |
* <P> Once the channel's socket has been successfully bound to a specific |
|
256 |
* address, that is not automatically assigned, more addresses |
|
257 |
* may be bound to it using {@link #bindAddress bindAddress}, or removed |
|
258 |
* using {@link #unbindAddress unbindAddress}. |
|
259 |
* |
|
260 |
* @param local |
|
261 |
* The local address to bind the socket, or {@code null} to |
|
262 |
* bind the socket to an automatically assigned socket address |
|
263 |
* |
|
264 |
* @return This channel |
|
265 |
* |
|
266 |
* @throws java.nio.channels.AlreadyConnectedException |
|
267 |
* If this channel is already connected |
|
268 |
* |
|
269 |
* @throws java.nio.channels.ClosedChannelException |
|
270 |
* If this channel is closed |
|
271 |
* |
|
272 |
* @throws java.nio.channels.ConnectionPendingException |
|
273 |
* If a non-blocking connection operation is already in progress on this channel |
|
274 |
* |
|
275 |
* @throws java.nio.channels.AlreadyBoundException |
|
276 |
* If this channel is already bound |
|
277 |
* |
|
278 |
* @throws java.nio.channels.UnsupportedAddressTypeException |
|
279 |
* If the type of the given address is not supported |
|
280 |
* |
|
281 |
* @throws IOException |
|
282 |
* If some other I/O error occurs |
|
22339 | 283 |
* |
284 |
* @throws SecurityException |
|
285 |
* If a security manager has been installed and its |
|
286 |
* {@link SecurityManager#checkListen checkListen} method denies |
|
287 |
* the operation |
|
2542 | 288 |
*/ |
289 |
public abstract SctpChannel bind(SocketAddress local) |
|
290 |
throws IOException; |
|
291 |
||
292 |
/** |
|
293 |
* Adds the given address to the bound addresses for the channel's |
|
294 |
* socket. |
|
295 |
* |
|
296 |
* <P> The given address must not be the {@link |
|
297 |
* java.net.InetAddress#isAnyLocalAddress wildcard} address. |
|
298 |
* The channel must be first bound using {@link #bind bind} before |
|
299 |
* invoking this method, otherwise {@link |
|
300 |
* java.nio.channels.NotYetBoundException} is thrown. The {@link #bind bind} |
|
301 |
* method takes a {@code SocketAddress} as its argument which typically |
|
302 |
* contains a port number as well as an address. Addresses subquently bound |
|
303 |
* using this method are simply addresses as the SCTP port number remains |
|
304 |
* the same for the lifetime of the channel. |
|
305 |
* |
|
306 |
* <P> Adding addresses to a connected association is optional functionality. |
|
307 |
* If the endpoint supports dynamic address reconfiguration then it may |
|
308 |
* send the appropriate message to the peer to change the peers address |
|
309 |
* lists. |
|
310 |
* |
|
311 |
* @param address |
|
312 |
* The address to add to the bound addresses for the socket |
|
313 |
* |
|
314 |
* @return This channel |
|
315 |
* |
|
316 |
* @throws java.nio.channels.ClosedChannelException |
|
317 |
* If this channel is closed |
|
318 |
* |
|
319 |
* @throws java.nio.channels.ConnectionPendingException |
|
320 |
* If a non-blocking connection operation is already in progress on |
|
321 |
* this channel |
|
322 |
* |
|
323 |
* @throws java.nio.channels.NotYetBoundException |
|
324 |
* If this channel is not yet bound |
|
325 |
* |
|
326 |
* @throws java.nio.channels.AlreadyBoundException |
|
327 |
* If this channel is already bound to the given address |
|
328 |
* |
|
329 |
* @throws IllegalArgumentException |
|
330 |
* If address is {@code null} or the {@link |
|
331 |
* java.net.InetAddress#isAnyLocalAddress wildcard} address |
|
332 |
* |
|
333 |
* @throws IOException |
|
334 |
* If some other I/O error occurs |
|
335 |
*/ |
|
336 |
public abstract SctpChannel bindAddress(InetAddress address) |
|
337 |
throws IOException; |
|
338 |
||
339 |
/** |
|
340 |
* Removes the given address from the bound addresses for the channel's |
|
341 |
* socket. |
|
342 |
* |
|
343 |
* <P> The given address must not be the {@link |
|
344 |
* java.net.InetAddress#isAnyLocalAddress wildcard} address. |
|
345 |
* The channel must be first bound using {@link #bind bind} before |
|
346 |
* invoking this method, otherwise {@link java.nio.channels.NotYetBoundException} |
|
347 |
* is thrown. If this method is invoked on a channel that does not have |
|
348 |
* {@code address} as one of its bound addresses or that has only one |
|
349 |
* local address bound to it, then this method throws |
|
350 |
* {@link IllegalUnbindException}. |
|
351 |
* The initial address that the channel's socket is bound to using {@link |
|
352 |
* #bind bind} may be removed from the bound addresses for the channel's socket. |
|
353 |
* |
|
354 |
* <P> Removing addresses from a connected association is optional |
|
355 |
* functionality. If the endpoint supports dynamic address reconfiguration |
|
356 |
* then it may send the appropriate message to the peer to change the peers |
|
357 |
* address lists. |
|
358 |
* |
|
359 |
* @param address |
|
360 |
* The address to remove from the bound addresses for the socket |
|
361 |
* |
|
362 |
* @return This channel |
|
363 |
* |
|
364 |
* @throws java.nio.channels.ClosedChannelException |
|
365 |
* If this channel is closed |
|
366 |
* |
|
367 |
* @throws java.nio.channels.ConnectionPendingException |
|
368 |
* If a non-blocking connection operation is already in progress on |
|
369 |
* this channel |
|
370 |
* |
|
371 |
* @throws java.nio.channels.NotYetBoundException |
|
372 |
* If this channel is not yet bound |
|
373 |
* |
|
374 |
* @throws IllegalArgumentException |
|
375 |
* If address is {@code null} or the {@link |
|
376 |
* java.net.InetAddress#isAnyLocalAddress wildcard} address |
|
377 |
* |
|
378 |
* @throws IllegalUnbindException |
|
379 |
* If {@code address} is not bound to the channel's socket. or |
|
380 |
* the channel has only one address bound to it |
|
381 |
* |
|
382 |
* @throws IOException |
|
383 |
* If some other I/O error occurs |
|
384 |
*/ |
|
385 |
public abstract SctpChannel unbindAddress(InetAddress address) |
|
386 |
throws IOException; |
|
387 |
||
388 |
/** |
|
389 |
* Connects this channel's socket. |
|
390 |
* |
|
391 |
* <P> If this channel is in non-blocking mode then an invocation of this |
|
392 |
* method initiates a non-blocking connection operation. If the connection |
|
393 |
* is established immediately, as can happen with a local connection, then |
|
394 |
* this method returns {@code true}. Otherwise this method returns |
|
395 |
* {@code false} and the connection operation must later be completed by |
|
396 |
* invoking the {@link #finishConnect finishConnect} method. |
|
397 |
* |
|
398 |
* <P> If this channel is in blocking mode then an invocation of this |
|
399 |
* method will block until the connection is established or an I/O error |
|
400 |
* occurs. |
|
401 |
* |
|
402 |
* <P> If a security manager has been installed then this method verifies |
|
403 |
* that its {@link java.lang.SecurityManager#checkConnect checkConnect} |
|
404 |
* method permits connecting to the address and port number of the given |
|
405 |
* remote peer. |
|
406 |
* |
|
407 |
* <p> This method may be invoked at any time. If a {@link #send send} or |
|
408 |
* {@link #receive receive} operation upon this channel is invoked while an |
|
409 |
* invocation of this method is in progress then that operation will first |
|
410 |
* block until this invocation is complete. If a connection attempt is |
|
411 |
* initiated but fails, that is, if an invocation of this method throws a |
|
412 |
* checked exception, then the channel will be closed. |
|
413 |
* |
|
414 |
* @param remote |
|
415 |
* The remote peer to which this channel is to be connected |
|
416 |
* |
|
417 |
* @return {@code true} if a connection was established, {@code false} if |
|
418 |
* this channel is in non-blocking mode and the connection |
|
419 |
* operation is in progress |
|
420 |
* |
|
421 |
* @throws java.nio.channels.AlreadyConnectedException |
|
422 |
* If this channel is already connected |
|
423 |
* |
|
424 |
* @throws java.nio.channels.ConnectionPendingException |
|
425 |
* If a non-blocking connection operation is already in progress on |
|
426 |
* this channel |
|
427 |
* |
|
428 |
* @throws java.nio.channels.ClosedChannelException |
|
429 |
* If this channel is closed |
|
430 |
* |
|
431 |
* @throws java.nio.channels.AsynchronousCloseException |
|
432 |
* If another thread closes this channel |
|
433 |
* while the connect operation is in progress |
|
434 |
* |
|
435 |
* @throws java.nio.channels.ClosedByInterruptException |
|
436 |
* If another thread interrupts the current thread |
|
437 |
* while the connect operation is in progress, thereby |
|
438 |
* closing the channel and setting the current thread's |
|
439 |
* interrupt status |
|
440 |
* |
|
441 |
* @throws java.nio.channels.UnresolvedAddressException |
|
442 |
* If the given remote address is not fully resolved |
|
443 |
* |
|
444 |
* @throws java.nio.channels.UnsupportedAddressTypeException |
|
445 |
* If the type of the given remote address is not supported |
|
446 |
* |
|
447 |
* @throws SecurityException |
|
448 |
* If a security manager has been installed |
|
449 |
* and it does not permit access to the given remote peer |
|
450 |
* |
|
451 |
* @throws IOException |
|
452 |
* If some other I/O error occurs |
|
453 |
*/ |
|
454 |
public abstract boolean connect(SocketAddress remote) throws IOException; |
|
455 |
||
456 |
/** |
|
457 |
* Connects this channel's socket. |
|
458 |
* |
|
459 |
* <P> This is a convience method and is equivalent to evaluating the |
|
460 |
* following expression: |
|
461 |
* <blockquote><pre> |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
462 |
* setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, SctpStandardSocketOption.InitMaxStreams.create(maxInStreams, maxOutStreams)) |
2542 | 463 |
* .connect(remote); |
464 |
* </pre></blockquote> |
|
465 |
* |
|
466 |
* <P> The {@code maxOutStreams} and {@code maxInStreams} parameters |
|
467 |
* represent the maximum number of streams that the application wishes to be |
|
468 |
* able to send to and receive from. They are negotiated with the remote |
|
469 |
* peer and may be limited by the operating system. |
|
470 |
* |
|
471 |
* @param remote |
|
472 |
* The remote peer to which this channel is to be connected |
|
473 |
* |
|
474 |
* @param maxOutStreams |
|
475 |
* Must be non negative and no larger than {@code 65536}. |
|
476 |
* {@code 0} to use the endpoints default value. |
|
477 |
* |
|
478 |
* @param maxInStreams |
|
479 |
* Must be non negative and no larger than {@code 65536}. |
|
480 |
* {@code 0} to use the endpoints default value. |
|
481 |
* |
|
482 |
* @return {@code true} if a connection was established, {@code false} if |
|
483 |
* this channel is in non-blocking mode and the connection operation |
|
484 |
* is in progress |
|
485 |
* |
|
486 |
* @throws java.nio.channels.AlreadyConnectedException |
|
487 |
* If this channel is already connected |
|
488 |
* |
|
489 |
* @throws java.nio.channels.ConnectionPendingException |
|
490 |
* If a non-blocking connection operation is already in progress on |
|
491 |
* this channel |
|
492 |
* |
|
493 |
* @throws java.nio.channels.ClosedChannelException |
|
494 |
* If this channel is closed |
|
495 |
* |
|
496 |
* @throws java.nio.channels.AsynchronousCloseException |
|
497 |
* If another thread closes this channel |
|
498 |
* while the connect operation is in progress |
|
499 |
* |
|
500 |
* @throws java.nio.channels.ClosedByInterruptException |
|
501 |
* If another thread interrupts the current thread |
|
502 |
* while the connect operation is in progress, thereby |
|
503 |
* closing the channel and setting the current thread's |
|
504 |
* interrupt status |
|
505 |
* |
|
506 |
* @throws java.nio.channels.UnresolvedAddressException |
|
507 |
* If the given remote address is not fully resolved |
|
508 |
* |
|
509 |
* @throws java.nio.channels.UnsupportedAddressTypeException |
|
510 |
* If the type of the given remote address is not supported |
|
511 |
* |
|
512 |
* @throws SecurityException |
|
513 |
* If a security manager has been installed |
|
514 |
* and it does not permit access to the given remote peer |
|
515 |
* |
|
516 |
* @throws IOException |
|
517 |
* If some other I/O error occurs |
|
518 |
*/ |
|
519 |
public abstract boolean connect(SocketAddress remote, |
|
520 |
int maxOutStreams, |
|
521 |
int maxInStreams) |
|
522 |
throws IOException; |
|
523 |
||
524 |
/** |
|
525 |
* Tells whether or not a connection operation is in progress on this channel. |
|
526 |
* |
|
527 |
* @return {@code true} if, and only if, a connection operation has been initiated |
|
528 |
* on this channel but not yet completed by invoking the |
|
529 |
* {@link #finishConnect} method |
|
530 |
*/ |
|
531 |
public abstract boolean isConnectionPending(); |
|
532 |
||
533 |
/** |
|
534 |
* Finishes the process of connecting an SCTP channel. |
|
535 |
* |
|
536 |
* <P> A non-blocking connection operation is initiated by placing a socket |
|
537 |
* channel in non-blocking mode and then invoking one of its {@link #connect |
|
538 |
* connect} methods. Once the connection is established, or the attempt has |
|
539 |
* failed, the channel will become connectable and this method may |
|
540 |
* be invoked to complete the connection sequence. If the connection |
|
541 |
* operation failed then invoking this method will cause an appropriate |
|
542 |
* {@link java.io.IOException} to be thrown. |
|
543 |
* |
|
544 |
* <P> If this channel is already connected then this method will not block |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
545 |
* and will immediately return {@code true}. If this channel is in |
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
546 |
* non-blocking mode then this method will return {@code false} if the |
2542 | 547 |
* connection process is not yet complete. If this channel is in blocking |
548 |
* mode then this method will block until the connection either completes |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
549 |
* or fails, and will always either return {@code true} or throw a checked |
2542 | 550 |
* exception describing the failure. |
551 |
* |
|
552 |
* <P> This method may be invoked at any time. If a {@link #send send} or {@link #receive receive} |
|
553 |
* operation upon this channel is invoked while an invocation of this |
|
554 |
* method is in progress then that operation will first block until this |
|
555 |
* invocation is complete. If a connection attempt fails, that is, if an |
|
556 |
* invocation of this method throws a checked exception, then the channel |
|
557 |
* will be closed. |
|
558 |
* |
|
559 |
* @return {@code true} if, and only if, this channel's socket is now |
|
560 |
* connected |
|
561 |
* |
|
562 |
* @throws java.nio.channels.NoConnectionPendingException |
|
563 |
* If this channel is not connected and a connection operation |
|
564 |
* has not been initiated |
|
565 |
* |
|
566 |
* @throws java.nio.channels.ClosedChannelException |
|
567 |
* If this channel is closed |
|
568 |
* |
|
569 |
* @throws java.nio.channels.AsynchronousCloseException |
|
570 |
* If another thread closes this channel |
|
571 |
* while the connect operation is in progress |
|
572 |
* |
|
573 |
* @throws java.nio.channels.ClosedByInterruptException |
|
574 |
* If another thread interrupts the current thread |
|
575 |
* while the connect operation is in progress, thereby |
|
576 |
* closing the channel and setting the current thread's |
|
577 |
* interrupt status |
|
578 |
* |
|
579 |
* @throws IOException |
|
580 |
* If some other I/O error occurs |
|
581 |
*/ |
|
582 |
public abstract boolean finishConnect() throws IOException; |
|
583 |
||
584 |
/** |
|
585 |
* Returns all of the socket addresses to which this channel's socket is |
|
586 |
* bound. |
|
587 |
* |
|
588 |
* @return All the socket addresses that this channel's socket is |
|
589 |
* bound to, or an empty {@code Set} if the channel's socket is not |
|
590 |
* bound |
|
591 |
* |
|
592 |
* @throws ClosedChannelException |
|
593 |
* If the channel is closed |
|
594 |
* |
|
595 |
* @throws IOException |
|
596 |
* If an I/O error occurs |
|
597 |
*/ |
|
598 |
public abstract Set<SocketAddress> getAllLocalAddresses() |
|
599 |
throws IOException; |
|
600 |
||
601 |
/** |
|
602 |
* Returns all of the remote addresses to which this channel's socket |
|
603 |
* is connected. |
|
604 |
* |
|
605 |
* <P> If the channel is connected to a remote peer that is bound to |
|
606 |
* multiple addresses then it is these addresses that the channel's socket |
|
607 |
* is connected. |
|
608 |
* |
|
609 |
* @return All of the remote addresses to which this channel's socket |
|
610 |
* is connected, or an empty {@code Set} if the channel's socket is |
|
611 |
* not connected |
|
612 |
* |
|
613 |
* @throws ClosedChannelException |
|
614 |
* If the channel is closed |
|
615 |
* |
|
616 |
* @throws IOException |
|
617 |
* If an I/O error occurs |
|
618 |
*/ |
|
619 |
public abstract Set<SocketAddress> getRemoteAddresses() |
|
620 |
throws IOException; |
|
621 |
||
622 |
/** |
|
623 |
* Shutdown a connection without closing the channel. |
|
624 |
* |
|
625 |
* <P> Sends a shutdown command to the remote peer, effectively preventing |
|
626 |
* any new data from being written to the socket by either peer. Further |
|
627 |
* sends will throw {@link java.nio.channels.ClosedChannelException}. The |
|
628 |
* channel remains open to allow the for any data (and notifications) to be |
|
629 |
* received that may have been sent by the peer before it received the |
|
630 |
* shutdown command. If the channel is already shutdown then invoking this |
|
631 |
* method has no effect. |
|
632 |
* |
|
633 |
* @return This channel |
|
634 |
* |
|
635 |
* @throws java.nio.channels.NotYetConnectedException |
|
636 |
* If this channel is not yet connected |
|
637 |
* |
|
638 |
* @throws java.nio.channels.ClosedChannelException |
|
639 |
* If this channel is closed |
|
640 |
* |
|
641 |
* @throws IOException |
|
642 |
* If some other I/O error occurs |
|
643 |
*/ |
|
644 |
public abstract SctpChannel shutdown() throws IOException; |
|
645 |
||
646 |
/** |
|
647 |
* Returns the value of a socket option. |
|
648 |
* |
|
19835 | 649 |
* @param <T> |
650 |
* The type of the socket option value |
|
651 |
* |
|
2542 | 652 |
* @param name |
653 |
* The socket option |
|
654 |
* |
|
655 |
* @return The value of the socket option. A value of {@code null} may be |
|
656 |
* a valid value for some socket options. |
|
657 |
* |
|
658 |
* @throws UnsupportedOperationException |
|
659 |
* If the socket option is not supported by this channel |
|
660 |
* |
|
661 |
* @throws ClosedChannelException |
|
662 |
* If this channel is closed |
|
663 |
* |
|
664 |
* @throws IOException |
|
665 |
* If an I/O error occurs |
|
666 |
* |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
667 |
* @see SctpStandardSocketOptions |
2542 | 668 |
*/ |
669 |
public abstract <T> T getOption(SctpSocketOption<T> name) |
|
670 |
throws IOException; |
|
671 |
||
672 |
/** |
|
673 |
* Sets the value of a socket option. |
|
674 |
* |
|
19835 | 675 |
* @param <T> |
676 |
* The type of the socket option value |
|
677 |
* |
|
2542 | 678 |
* @param name |
679 |
* The socket option |
|
680 |
* |
|
681 |
* @param value |
|
682 |
* The value of the socket option. A value of {@code null} may be |
|
683 |
* a valid value for some socket options. |
|
684 |
* |
|
685 |
* @return This channel |
|
686 |
* |
|
687 |
* @throws UnsupportedOperationException |
|
688 |
* If the socket option is not supported by this channel |
|
689 |
* |
|
690 |
* @throws IllegalArgumentException |
|
691 |
* If the value is not a valid value for this socket option |
|
692 |
* |
|
693 |
* @throws ClosedChannelException |
|
694 |
* If this channel is closed |
|
695 |
* |
|
696 |
* @throws IOException |
|
697 |
* If an I/O error occurs |
|
698 |
* |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
699 |
* @see SctpStandardSocketOptions |
2542 | 700 |
*/ |
701 |
public abstract <T> SctpChannel setOption(SctpSocketOption<T> name, T value) |
|
702 |
throws IOException; |
|
703 |
||
704 |
/** |
|
705 |
* Returns a set of the socket options supported by this channel. |
|
706 |
* |
|
707 |
* <P> This method will continue to return the set of options even after the |
|
708 |
* channel has been closed. |
|
709 |
* |
|
710 |
* @return A set of the socket options supported by this channel |
|
711 |
*/ |
|
712 |
public abstract Set<SctpSocketOption<?>> supportedOptions(); |
|
713 |
||
714 |
/** |
|
715 |
* Returns an operation set identifying this channel's supported operations. |
|
716 |
* |
|
717 |
* <P> SCTP channels support connecting, reading, and writing, so this |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
718 |
* method returns {@code (}{@link SelectionKey#OP_CONNECT} |
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
719 |
* {@code |} {@link SelectionKey#OP_READ} {@code |} {@link |
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
720 |
* SelectionKey#OP_WRITE}{@code )}. |
2542 | 721 |
* |
722 |
* @return The valid-operation set |
|
723 |
*/ |
|
724 |
@Override |
|
725 |
public final int validOps() { |
|
726 |
return (SelectionKey.OP_READ | |
|
727 |
SelectionKey.OP_WRITE | |
|
728 |
SelectionKey.OP_CONNECT); |
|
729 |
} |
|
730 |
||
731 |
/** |
|
732 |
* Receives a message into the given buffer and/or handles a notification. |
|
733 |
* |
|
734 |
* <P> If a message or notification is immediately available, or if this |
|
735 |
* channel is in blocking mode and one eventually becomes available, then |
|
736 |
* the message or notification is returned or handled, respectively. If this |
|
737 |
* channel is in non-blocking mode and a message or notification is not |
|
738 |
* immediately available then this method immediately returns {@code null}. |
|
739 |
* |
|
740 |
* <P> If this method receives a message it is copied into the given byte |
|
741 |
* buffer. The message is transferred into the given byte buffer starting at |
|
742 |
* its current position and the buffers position is incremented by the |
|
743 |
* number of bytes read. If there are fewer bytes remaining in the buffer |
|
744 |
* than are required to hold the message, or the underlying input buffer |
|
745 |
* does not contain the complete message, then an invocation of {@link |
|
746 |
* MessageInfo#isComplete isComplete} on the returned {@code |
|
747 |
* MessageInfo} will return {@code false}, and more invocations of this |
|
748 |
* method will be necessary to completely consume the messgae. Only |
|
749 |
* one message at a time will be partially delivered in any stream. The |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
750 |
* socket option {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE |
2542 | 751 |
* SCTP_FRAGMENT_INTERLEAVE} controls various aspects of what interlacing of |
752 |
* messages occurs. |
|
753 |
* |
|
754 |
* <P> If this method receives a notification then the appropriate method of |
|
755 |
* the given handler, if there is one, is invoked. If the handler returns |
|
756 |
* {@link HandlerResult#CONTINUE CONTINUE} then this method will try to |
|
757 |
* receive another message/notification, otherwise, if {@link |
|
758 |
* HandlerResult#RETURN RETURN} is returned this method will return {@code |
|
759 |
* null}. If an uncaught exception is thrown by the handler it will be |
|
760 |
* propagated up the stack through this method. |
|
761 |
* |
|
762 |
* <P> This method may be invoked at any time. If another thread has |
|
763 |
* already initiated a receive operation upon this channel, then an |
|
764 |
* invocation of this method will block until the first operation is |
|
765 |
* complete. The given handler is invoked without holding any locks used |
|
766 |
* to enforce the above synchronization policy, that way handlers |
|
767 |
* will not stall other threads from receiving. A handler should not invoke |
|
768 |
* the {@code receive} method of this channel, if it does an |
|
769 |
* {@link IllegalReceiveException} will be thrown. |
|
770 |
* |
|
19835 | 771 |
* @param <T> |
772 |
* The type of the attachment |
|
773 |
* |
|
2542 | 774 |
* @param dst |
775 |
* The buffer into which message bytes are to be transferred |
|
776 |
* |
|
777 |
* @param attachment |
|
778 |
* The object to attach to the receive operation; can be |
|
779 |
* {@code null} |
|
780 |
* |
|
781 |
* @param handler |
|
782 |
* A handler to handle notifications from the SCTP stack, or {@code |
|
783 |
* null} to ignore any notifications. |
|
784 |
* |
|
785 |
* @return The {@code MessageInfo}, {@code null} if this channel is in |
|
786 |
* non-blocking mode and no messages are immediately available or |
|
787 |
* the notification handler returns {@link HandlerResult#RETURN |
|
788 |
* RETURN} after handling a notification |
|
789 |
* |
|
790 |
* @throws java.nio.channels.ClosedChannelException |
|
791 |
* If this channel is closed |
|
792 |
* |
|
793 |
* @throws java.nio.channels.AsynchronousCloseException |
|
794 |
* If another thread closes this channel |
|
795 |
* while the read operation is in progress |
|
796 |
* |
|
797 |
* @throws java.nio.channels.ClosedByInterruptException |
|
798 |
* If another thread interrupts the current thread |
|
799 |
* while the read operation is in progress, thereby |
|
800 |
* closing the channel and setting the current thread's |
|
801 |
* interrupt status |
|
802 |
* |
|
803 |
* @throws java.nio.channels.NotYetConnectedException |
|
804 |
* If this channel is not yet connected |
|
805 |
* |
|
806 |
* @throws IllegalReceiveException |
|
807 |
* If the given handler invokes the {@code receive} method of this |
|
808 |
* channel |
|
809 |
* |
|
810 |
* @throws IOException |
|
811 |
* If some other I/O error occurs |
|
812 |
*/ |
|
813 |
public abstract <T> MessageInfo receive(ByteBuffer dst, |
|
814 |
T attachment, |
|
815 |
NotificationHandler<T> handler) |
|
816 |
throws IOException; |
|
817 |
||
818 |
/** |
|
819 |
* Sends a message via this channel. |
|
820 |
* |
|
821 |
* <P> If this channel is in non-blocking mode and there is sufficient room |
|
822 |
* in the underlying output buffer, or if this channel is in blocking mode |
|
823 |
* and sufficient room becomes available, then the remaining bytes in the |
|
824 |
* given byte buffer are transmitted as a single message. Sending a message |
|
825 |
* is atomic unless explicit message completion {@link |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
5506
diff
changeset
|
826 |
* SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE SCTP_EXPLICIT_COMPLETE} |
2542 | 827 |
* socket option is enabled on this channel's socket. |
828 |
* |
|
829 |
* <P> The message is transferred from the byte buffer as if by a regular |
|
830 |
* {@link java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer) |
|
831 |
* write} operation. |
|
832 |
* |
|
833 |
* <P> The bytes will be written to the stream number that is specified by |
|
834 |
* {@link MessageInfo#streamNumber streamNumber} in the given {@code |
|
835 |
* messageInfo}. |
|
836 |
* |
|
837 |
* <P> This method may be invoked at any time. If another thread has already |
|
838 |
* initiated a send operation upon this channel, then an invocation of |
|
839 |
* this method will block until the first operation is complete. |
|
840 |
* |
|
841 |
* @param src |
|
842 |
* The buffer containing the message to be sent |
|
843 |
* |
|
844 |
* @param messageInfo |
|
845 |
* Ancillary data about the message to be sent |
|
846 |
* |
|
847 |
* @return The number of bytes sent, which will be either the number of |
|
848 |
* bytes that were remaining in the messages buffer when this method |
|
849 |
* was invoked or, if this channel is non-blocking, may be zero if |
|
850 |
* there was insufficient room for the message in the underlying |
|
851 |
* output buffer |
|
852 |
* |
|
19835 | 853 |
* @throws InvalidStreamException |
2542 | 854 |
* If {@code streamNumner} is negative or greater than or equal to |
855 |
* the maximum number of outgoing streams |
|
856 |
* |
|
857 |
* @throws java.nio.channels.ClosedChannelException |
|
858 |
* If this channel is closed |
|
859 |
* |
|
860 |
* @throws java.nio.channels.AsynchronousCloseException |
|
861 |
* If another thread closes this channel |
|
862 |
* while the read operation is in progress |
|
863 |
* |
|
864 |
* @throws java.nio.channels.ClosedByInterruptException |
|
865 |
* If another thread interrupts the current thread |
|
866 |
* while the read operation is in progress, thereby |
|
867 |
* closing the channel and setting the current thread's |
|
868 |
* interrupt status |
|
869 |
* |
|
870 |
* @throws java.nio.channels.NotYetConnectedException |
|
871 |
* If this channel is not yet connected |
|
872 |
* |
|
873 |
* @throws IOException |
|
874 |
* If some other I/O error occurs |
|
875 |
*/ |
|
876 |
public abstract int send(ByteBuffer src, MessageInfo messageInfo) |
|
877 |
throws IOException; |
|
878 |
} |