Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/nio/sctp/SctpStandardSocketOptions.java
38923 views
1
/*
2
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
package com.sun.nio.sctp;
26
27
import java.net.SocketAddress;
28
import sun.nio.ch.sctp.SctpStdSocketOption;
29
30
/**
31
* SCTP channels supports the socket options defined by this class
32
* (as well as those listed in the particular channel class) and may support
33
* additional Implementation specific socket options.
34
*
35
* @since 1.7
36
*/
37
@jdk.Exported
38
public class SctpStandardSocketOptions {
39
private SctpStandardSocketOptions() {}
40
/**
41
* Enables or disables message fragmentation.
42
*
43
* <P> The value of this socket option is a {@code Boolean} that represents
44
* whether the option is enabled or disabled. If enabled no SCTP message
45
* fragmentation will be performed. Instead if a message being sent
46
* exceeds the current PMTU size, the message will NOT be sent and
47
* an error will be indicated to the user.
48
*
49
* <P> It is implementation specific whether or not this option is
50
* supported.
51
*/
52
public static final SctpSocketOption<Boolean> SCTP_DISABLE_FRAGMENTS = new
53
SctpStdSocketOption<Boolean>("SCTP_DISABLE_FRAGMENTS", Boolean.class,
54
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_DISABLE_FRAGMENTS);
55
56
/**
57
* Enables or disables explicit message completion.
58
*
59
* <p> The value of this socket option is a {@code Boolean} that represents
60
* whether the option is enabled or disabled. When this option is enabled,
61
* the {@code send} method may be invoked multiple times to a send message.
62
* The {@code isComplete} parameter of the {@link MessageInfo} must only
63
* be set to {@code true} for the final send to indicate that the message is
64
* complete. If this option is disabled then each individual {@code send}
65
* invocation is considered complete.
66
*
67
* <P> The default value of the option is {@code false} indicating that the
68
* option is disabled. It is implementation specific whether or not this
69
* option is supported.
70
*/
71
public static final SctpSocketOption<Boolean> SCTP_EXPLICIT_COMPLETE = new
72
SctpStdSocketOption<Boolean>("SCTP_EXPLICIT_COMPLETE", Boolean.class,
73
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_EXPLICIT_COMPLETE);
74
75
/**
76
* Fragmented interleave controls how the presentation of messages occur
77
* for the message receiver. There are three levels of fragment interleave
78
* defined. Two of the levels effect {@link SctpChannel}, while
79
* {@link SctpMultiChannel} is effected by all three levels.
80
*
81
* <P> This option takes an {@code Integer} value. It can be set to a value
82
* of {@code 0}, {@code 1} or {@code 2}.
83
*
84
* <P> Setting the three levels provides the following receiver
85
* interactions:
86
*
87
* <P> {@code level 0} - Prevents the interleaving of any messages. This
88
* means that when a partial delivery begins, no other messages will be
89
* received except the message being partially delivered. If another message
90
* arrives on a different stream (or association) that could be delivered,
91
* it will be blocked waiting for the user to read all of the partially
92
* delivered message.
93
*
94
* <P> {@code level 1} - Allows interleaving of messages that are from
95
* different associations. For {@code SctpChannel}, level 0 and
96
* level 1 have the same meaning since an {@code SctpChannel} always
97
* receives messages from the same association. Note that setting an {@code
98
* SctpMultiChannel} to this level may cause multiple partial
99
* delivers from different associations but for any given association, only
100
* one message will be delivered until all parts of a message have been
101
* delivered. This means that one large message, being read with an
102
* association identification of "X", will block other messages from
103
* association "X" from being delivered.
104
*
105
* <P> {@code level 2} - Allows complete interleaving of messages. This
106
* level requires that the sender carefully observe not only the peer
107
* {@code Association} but also must pay careful attention to the stream
108
* number. With this option enabled a partially delivered message may begin
109
* being delivered for association "X" stream "Y" and the next subsequent
110
* receive may return a message from association "X" stream "Z". Note that
111
* no other messages would be delivered for association "X" stream "Y"
112
* until all of stream "Y"'s partially delivered message was read.
113
* Note that this option effects both channel types. Also note that
114
* for an {@code SctpMultiChannel} not only may another streams
115
* message from the same association be delivered from the next receive,
116
* some other associations message may be delivered upon the next receive.
117
*
118
* <P> It is implementation specific whether or not this option is
119
* supported.
120
*/
121
public static final SctpSocketOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
122
new SctpStdSocketOption<Integer>("SCTP_FRAGMENT_INTERLEAVE",
123
Integer.class,
124
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_FRAGMENT_INTERLEAVE);
125
126
/**
127
* The maximum number of streams requested by the local endpoint during
128
* association initialization.
129
*
130
* <P> The value of this socket option is an {@link
131
* SctpStandardSocketOptions.InitMaxStreams InitMaxStreams}, that represents
132
* the maximum number of inbound and outbound streams that an association
133
* on the channel is prepared to support.
134
*
135
* <P> For an {@link SctpChannel} this option may only be used to
136
* change the number of inbound/outbound streams prior to connecting.
137
*
138
* <P> For an {@link SctpMultiChannel} this option determines
139
* the maximum number of inbound/outbound streams new associations setup
140
* on the channel will be prepared to support.
141
*
142
* <P> For an {@link SctpServerChannel} this option determines the
143
* maximum number of inbound/outbound streams accepted sockets will
144
* negotiate with their connecting peer.
145
*
146
* <P> In all cases the value set by this option is used in the negotiation
147
* of new associations setup on the channel's socket and the actual
148
* maximum number of inbound/outbound streams that have been negotiated
149
* with the peer can be retrieved from the appropriate {@link
150
* Association}. The {@code Association} can be retrieved from the
151
* {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP COMM_UP}
152
* {@link AssociationChangeNotification} belonging to that association.
153
*
154
* <p> This value is bounded by the actual implementation. In other
155
* words the user may be able to support more streams than the Operating
156
* System. In such a case, the Operating System limit may override the
157
* value requested by the user. The default value of 0 indicates to use
158
* the endpoints default value.
159
*/
160
public static final SctpSocketOption
161
<SctpStandardSocketOptions.InitMaxStreams> SCTP_INIT_MAXSTREAMS =
162
new SctpStdSocketOption<SctpStandardSocketOptions.InitMaxStreams>(
163
"SCTP_INIT_MAXSTREAMS", SctpStandardSocketOptions.InitMaxStreams.class);
164
165
/**
166
* Enables or disables a Nagle-like algorithm.
167
*
168
* <P> The value of this socket option is a {@code Boolean} that represents
169
* whether the option is enabled or disabled. SCTP uses an algorithm like
170
* <em>The Nagle Algorithm</em> to coalesce short segments and
171
* improve network efficiency.
172
*/
173
public static final SctpSocketOption<Boolean> SCTP_NODELAY =
174
new SctpStdSocketOption<Boolean>("SCTP_NODELAY", Boolean.class,
175
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_NODELAY);
176
177
/**
178
* Requests that the local SCTP stack use the given peer address as
179
* the association primary.
180
*
181
* <P> The value of this socket option is a {@code SocketAddress}
182
* that represents the peer address that the local SCTP stack should use as
183
* the association primary. The address must be one of the association
184
* peer's addresses.
185
*
186
* <P> An {@code SctpMultiChannel} can control more than one
187
* association, the association parameter must be given when setting or
188
* retrieving this option.
189
*
190
* <P> Since {@code SctpChannel} only controls one association,
191
* the association parameter is not required and this option can be
192
* set or queried directly.
193
*/
194
public static final SctpSocketOption<SocketAddress> SCTP_PRIMARY_ADDR =
195
new SctpStdSocketOption<SocketAddress>
196
("SCTP_PRIMARY_ADDR", SocketAddress.class);
197
198
/**
199
* Requests that the peer mark the enclosed address as the association
200
* primary.
201
*
202
* <P> The value of this socket option is a {@code SocketAddress}
203
* that represents the local address that the peer should use as its
204
* primary address. The given address must be one of the association's
205
* locally bound addresses.
206
*
207
* <P> An {@code SctpMultiChannel} can control more than one
208
* association, the association parameter must be given when setting or
209
* retrieving this option.
210
*
211
* <P> Since {@code SctpChannel} only controls one association,
212
* the association parameter is not required and this option can be
213
* queried directly.
214
*
215
* <P> Note, this is a set only option and cannot be retrieved by {@code
216
* getOption}. It is implementation specific whether or not this
217
* option is supported.
218
*/
219
public static final SctpSocketOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
220
new SctpStdSocketOption<SocketAddress>
221
("SCTP_SET_PEER_PRIMARY_ADDR", SocketAddress.class);
222
223
/**
224
* The size of the socket send buffer.
225
*
226
* <p> The value of this socket option is an {@code Integer} that is the
227
* size of the socket send buffer in bytes. The socket send buffer is an
228
* output buffer used by the networking implementation. It may need to be
229
* increased for high-volume connections. The value of the socket option is
230
* a <em>hint</em> to the implementation to size the buffer and the actual
231
* size may differ. The socket option can be queried to retrieve the actual
232
* size.
233
*
234
* <p> For {@code SctpChannel}, this controls the amount of data
235
* the SCTP stack may have waiting in internal buffers to be sent. This
236
* option therefore bounds the maximum size of data that can be sent in a
237
* single send call.
238
*
239
* <P> For {@code SctpMultiChannel}, the effect is the same as for {@code
240
* SctpChannel}, except that it applies to all associations. The option
241
* applies to each association's window size separately.
242
*
243
* <p> An implementation allows this socket option to be set before the
244
* socket is bound or connected. Whether an implementation allows the
245
* socket send buffer to be changed after the socket is bound is system
246
* dependent.
247
*/
248
public static final SctpSocketOption<Integer> SO_SNDBUF =
249
new SctpStdSocketOption<Integer>("SO_SNDBUF", Integer.class,
250
sun.nio.ch.sctp.SctpStdSocketOption.SO_SNDBUF);
251
252
/**
253
* The size of the socket receive buffer.
254
*
255
* <P> The value of this socket option is an {@code Integer} that is the
256
* size of the socket receive buffer in bytes. The socket receive buffer is
257
* an input buffer used by the networking implementation. It may need to be
258
* increased for high-volume connections or decreased to limit the possible
259
* backlog of incoming data. The value of the socket option is a
260
* <em>hint</em> to the implementation to size the buffer and the actual
261
* size may differ.
262
*
263
* <P> For {@code SctpChannel}, this controls the receiver window size.
264
*
265
* <P> For {@code SctpMultiChannel}, the meaning is implementation
266
* dependent. It might control the receive buffer for each association bound
267
* to the socket descriptor or it might control the receive buffer for the
268
* whole socket.
269
*
270
* <p> An implementation allows this socket option to be set before the
271
* socket is bound or connected. Whether an implementation allows the
272
* socket receive buffer to be changed after the socket is bound is system
273
* dependent.
274
*/
275
public static final SctpSocketOption<Integer> SO_RCVBUF =
276
new SctpStdSocketOption<Integer>("SO_RCVBUF", Integer.class,
277
sun.nio.ch.sctp.SctpStdSocketOption.SO_RCVBUF);
278
279
/**
280
* Linger on close if data is present.
281
*
282
* <p> The value of this socket option is an {@code Integer} that controls
283
* the action taken when unsent data is queued on the socket and a method
284
* to close the socket is invoked. If the value of the socket option is zero
285
* or greater, then it represents a timeout value, in seconds, known as the
286
* <em>linger interval</em>. The linger interval is the timeout for the
287
* {@code close} method to block while the operating system attempts to
288
* transmit the unsent data or it decides that it is unable to transmit the
289
* data. If the value of the socket option is less than zero then the option
290
* is disabled. In that case the {@code close} method does not wait until
291
* unsent data is transmitted; if possible the operating system will transmit
292
* any unsent data before the connection is closed.
293
*
294
* <p> This socket option is intended for use with sockets that are configured
295
* in {@link java.nio.channels.SelectableChannel#isBlocking() blocking} mode
296
* only. The behavior of the {@code close} method when this option is
297
* enabled on a non-blocking socket is not defined.
298
*
299
* <p> The initial value of this socket option is a negative value, meaning
300
* that the option is disabled. The option may be enabled, or the linger
301
* interval changed, at any time. The maximum value of the linger interval
302
* is system dependent. Setting the linger interval to a value that is
303
* greater than its maximum value causes the linger interval to be set to
304
* its maximum value.
305
*/
306
public static final SctpSocketOption<Integer> SO_LINGER =
307
new SctpStdSocketOption<Integer>("SO_LINGER", Integer.class,
308
sun.nio.ch.sctp.SctpStdSocketOption.SO_LINGER);
309
310
/**
311
* This class is used to set the maximum number of inbound/outbound streams
312
* used by the local endpoint during association initialization. An
313
* instance of this class is used to set the {@link
314
* SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS SCTP_INIT_MAXSTREAMS}
315
* socket option.
316
*
317
* @since 1.7
318
*/
319
@jdk.Exported
320
public static class InitMaxStreams {
321
private int maxInStreams;
322
private int maxOutStreams;
323
324
private InitMaxStreams(int maxInStreams, int maxOutStreams) {
325
this.maxInStreams = maxInStreams;
326
this.maxOutStreams = maxOutStreams;
327
}
328
329
/**
330
* Creates an InitMaxStreams instance.
331
*
332
* @param maxInStreams
333
* The maximum number of inbound streams, where
334
* {@code 0 <= maxInStreams <= 65536}
335
*
336
* @param maxOutStreams
337
* The maximum number of outbound streams, where
338
* {@code 0 <= maxOutStreams <= 65536}
339
*
340
* @return An {@code InitMaxStreams} instance
341
*
342
* @throws IllegalArgumentException
343
* If an argument is outside of specified bounds
344
*/
345
public static InitMaxStreams create
346
(int maxInStreams, int maxOutStreams) {
347
if (maxOutStreams < 0 || maxOutStreams > 65535)
348
throw new IllegalArgumentException(
349
"Invalid maxOutStreams value");
350
if (maxInStreams < 0 || maxInStreams > 65535)
351
throw new IllegalArgumentException(
352
"Invalid maxInStreams value");
353
354
return new InitMaxStreams(maxInStreams, maxOutStreams);
355
}
356
357
/**
358
* Returns the maximum number of inbound streams.
359
*
360
* @return Maximum inbound streams
361
*/
362
public int maxInStreams() {
363
return maxInStreams;
364
}
365
366
/**
367
* Returns the maximum number of outbound streams.
368
*
369
* @return Maximum outbound streams
370
*/
371
public int maxOutStreams() {
372
return maxOutStreams;
373
}
374
375
/**
376
* Returns a string representation of this init max streams, including
377
* the maximum in and out bound streams.
378
*
379
* @return A string representation of this init max streams
380
*/
381
@Override
382
public String toString() {
383
StringBuilder sb = new StringBuilder();
384
sb.append(super.toString()).append(" [");
385
sb.append("maxInStreams:").append(maxInStreams);
386
sb.append("maxOutStreams:").append(maxOutStreams).append("]");
387
return sb.toString();
388
}
389
390
/**
391
* Returns true if the specified object is another {@code InitMaxStreams}
392
* instance with the same number of in and out bound streams.
393
*
394
* @param obj
395
* The object to be compared with this init max streams
396
*
397
* @return true if the specified object is another
398
* {@code InitMaxStreams} instance with the same number of in
399
* and out bound streams
400
*/
401
@Override
402
public boolean equals(Object obj) {
403
if (obj != null && obj instanceof InitMaxStreams) {
404
InitMaxStreams that = (InitMaxStreams) obj;
405
if (this.maxInStreams == that.maxInStreams &&
406
this.maxOutStreams == that.maxOutStreams)
407
return true;
408
}
409
return false;
410
}
411
412
/**
413
* Returns a hash code value for this init max streams.
414
*/
415
@Override
416
public int hashCode() {
417
int hash = 7 ^ maxInStreams ^ maxOutStreams;
418
return hash;
419
}
420
}
421
}
422
423