author | dfuchs |
Wed, 09 Oct 2019 17:38:58 +0100 | |
changeset 58518 | 705c3f88a409 |
parent 58501 | 6fc4a729763e |
child 58679 | 9c3209ff7550 |
child 58803 | 1bd307ea5497 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58518
705c3f88a409
8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents:
58501
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.nio.channels; |
|
27 |
||
28 |
import java.io.IOException; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
29 |
import java.net.ProtocolFamily; |
2 | 30 |
import java.net.DatagramSocket; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
31 |
import java.net.SocketOption; |
2 | 32 |
import java.net.SocketAddress; |
33 |
import java.nio.ByteBuffer; |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
34 |
import java.nio.channels.spi.AbstractSelectableChannel; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
35 |
import java.nio.channels.spi.SelectorProvider; |
2 | 36 |
|
37 |
/** |
|
38 |
* A selectable channel for datagram-oriented sockets. |
|
39 |
* |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
40 |
* <p> A datagram channel is created by invoking one of the {@link #open open} methods |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
41 |
* of this class. It is not possible to create a channel for an arbitrary, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
42 |
* pre-existing datagram socket. A newly-created datagram channel is open but not |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
43 |
* connected. A datagram channel need not be connected in order for the {@link #send |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
44 |
* send} and {@link #receive receive} methods to be used. A datagram channel may be |
2 | 45 |
* connected, by invoking its {@link #connect connect} method, in order to |
46 |
* avoid the overhead of the security checks are otherwise performed as part of |
|
47 |
* every send and receive operation. A datagram channel must be connected in |
|
48 |
* order to use the {@link #read(java.nio.ByteBuffer) read} and {@link |
|
49 |
* #write(java.nio.ByteBuffer) write} methods, since those methods do not |
|
50 |
* accept or return socket addresses. |
|
51 |
* |
|
52 |
* <p> Once connected, a datagram channel remains connected until it is |
|
53 |
* disconnected or closed. Whether or not a datagram channel is connected may |
|
54 |
* be determined by invoking its {@link #isConnected isConnected} method. |
|
55 |
* |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
56 |
* <p> Socket options are configured using the {@link #setOption(SocketOption,Object) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
57 |
* setOption} method. A datagram channel to an Internet Protocol socket supports |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
58 |
* the following options: |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
59 |
* <blockquote> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
60 |
* <table class="striped"> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
61 |
* <caption style="display:none">Socket options</caption> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
62 |
* <thead> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
63 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
64 |
* <th scope="col">Option Name</th> |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
65 |
* <th scope="col">Description</th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
66 |
* </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
67 |
* </thead> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
68 |
* <tbody> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
69 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
70 |
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
71 |
* <td> The size of the socket send buffer </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
72 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
73 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
74 |
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
75 |
* <td> The size of the socket receive buffer </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
76 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
77 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
78 |
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
79 |
* <td> Re-use address </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
80 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
81 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
82 |
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_BROADCAST SO_BROADCAST} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
83 |
* <td> Allow transmission of broadcast datagrams </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
84 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
85 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
86 |
* <th scope="row"> {@link java.net.StandardSocketOptions#IP_TOS IP_TOS} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
87 |
* <td> The Type of Service (ToS) octet in the Internet Protocol (IP) header </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
88 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
89 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
90 |
* <th scope="row"> {@link java.net.StandardSocketOptions#IP_MULTICAST_IF IP_MULTICAST_IF} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
91 |
* <td> The network interface for Internet Protocol (IP) multicast datagrams </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
92 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
93 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
94 |
* <th scope="row"> {@link java.net.StandardSocketOptions#IP_MULTICAST_TTL |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
95 |
* IP_MULTICAST_TTL} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
96 |
* <td> The <em>time-to-live</em> for Internet Protocol (IP) multicast |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
97 |
* datagrams </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
98 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
99 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
100 |
* <th scope="row"> {@link java.net.StandardSocketOptions#IP_MULTICAST_LOOP |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
101 |
* IP_MULTICAST_LOOP} </th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
102 |
* <td> Loopback for Internet Protocol (IP) multicast datagrams </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
103 |
* </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
104 |
* </tbody> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
105 |
* </table> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
106 |
* </blockquote> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
107 |
* Additional (implementation specific) options may also be supported. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
108 |
* |
2 | 109 |
* <p> Datagram channels are safe for use by multiple concurrent threads. They |
110 |
* support concurrent reading and writing, though at most one thread may be |
|
111 |
* reading and at most one thread may be writing at any given time. </p> |
|
112 |
* |
|
113 |
* @author Mark Reinhold |
|
114 |
* @author JSR-51 Expert Group |
|
115 |
* @since 1.4 |
|
116 |
*/ |
|
117 |
||
118 |
public abstract class DatagramChannel |
|
119 |
extends AbstractSelectableChannel |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
120 |
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, MulticastChannel |
2 | 121 |
{ |
122 |
||
123 |
/** |
|
124 |
* Initializes a new instance of this class. |
|
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18212
diff
changeset
|
125 |
* |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18212
diff
changeset
|
126 |
* @param provider |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18212
diff
changeset
|
127 |
* The provider that created this channel |
2 | 128 |
*/ |
129 |
protected DatagramChannel(SelectorProvider provider) { |
|
130 |
super(provider); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Opens a datagram channel. |
|
135 |
* |
|
136 |
* <p> The new channel is created by invoking the {@link |
|
137 |
* java.nio.channels.spi.SelectorProvider#openDatagramChannel() |
|
138 |
* openDatagramChannel} method of the system-wide default {@link |
|
139 |
* java.nio.channels.spi.SelectorProvider} object. The channel will not be |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
140 |
* connected. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
141 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
142 |
* <p> The {@link ProtocolFamily ProtocolFamily} of the channel's socket |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
143 |
* is platform (and possibly configuration) dependent and therefore unspecified. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
144 |
* The {@link #open(ProtocolFamily) open} allows the protocol family to be |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
145 |
* selected when opening a datagram channel, and should be used to open |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
146 |
* datagram channels that are intended for Internet Protocol multicasting. |
2 | 147 |
* |
148 |
* @return A new datagram channel |
|
149 |
* |
|
150 |
* @throws IOException |
|
151 |
* If an I/O error occurs |
|
152 |
*/ |
|
153 |
public static DatagramChannel open() throws IOException { |
|
154 |
return SelectorProvider.provider().openDatagramChannel(); |
|
155 |
} |
|
156 |
||
157 |
/** |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
158 |
* Opens a datagram channel. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
159 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
160 |
* <p> The {@code family} parameter is used to specify the {@link |
21278 | 161 |
* ProtocolFamily}. If the datagram channel is to be used for IP multicasting |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
162 |
* then this should correspond to the address type of the multicast groups |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
163 |
* that this channel will join. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
164 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
165 |
* <p> The new channel is created by invoking the {@link |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
166 |
* java.nio.channels.spi.SelectorProvider#openDatagramChannel(ProtocolFamily) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
167 |
* openDatagramChannel} method of the system-wide default {@link |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
168 |
* java.nio.channels.spi.SelectorProvider} object. The channel will not be |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
169 |
* connected. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
170 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
171 |
* @param family |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
172 |
* The protocol family |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
173 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
174 |
* @return A new datagram channel |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
175 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
176 |
* @throws UnsupportedOperationException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
177 |
* If the specified protocol family is not supported. For example, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
178 |
* suppose the parameter is specified as {@link |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
179 |
* java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
180 |
* but IPv6 is not enabled on the platform. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
181 |
* @throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
182 |
* If an I/O error occurs |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
183 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
184 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
185 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
186 |
public static DatagramChannel open(ProtocolFamily family) throws IOException { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
187 |
return SelectorProvider.provider().openDatagramChannel(family); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
188 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
189 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
190 |
/** |
2 | 191 |
* Returns an operation set identifying this channel's supported |
192 |
* operations. |
|
193 |
* |
|
194 |
* <p> Datagram channels support reading and writing, so this method |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
195 |
* returns {@code (}{@link SelectionKey#OP_READ} {@code |} {@link |
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
196 |
* SelectionKey#OP_WRITE}{@code )}. |
2 | 197 |
* |
198 |
* @return The valid-operation set |
|
199 |
*/ |
|
200 |
public final int validOps() { |
|
201 |
return (SelectionKey.OP_READ |
|
202 |
| SelectionKey.OP_WRITE); |
|
203 |
} |
|
204 |
||
205 |
||
206 |
// -- Socket-specific operations -- |
|
207 |
||
208 |
/** |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
209 |
* @throws AlreadyBoundException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
210 |
* @throws UnsupportedAddressTypeException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
211 |
* @throws ClosedChannelException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
212 |
* @throws IOException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
213 |
* @throws SecurityException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
214 |
* If a security manager has been installed and its {@link |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
215 |
* SecurityManager#checkListen checkListen} method denies the |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
216 |
* operation |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
217 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
218 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
219 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
220 |
public abstract DatagramChannel bind(SocketAddress local) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
221 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
222 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
223 |
/** |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
224 |
* @throws UnsupportedOperationException {@inheritDoc} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
225 |
* @throws IllegalArgumentException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
226 |
* @throws ClosedChannelException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
227 |
* @throws IOException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
228 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
229 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
230 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
231 |
public abstract <T> DatagramChannel setOption(SocketOption<T> name, T value) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
232 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
233 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
234 |
/** |
2 | 235 |
* Retrieves a datagram socket associated with this channel. |
236 |
* |
|
237 |
* <p> The returned object will not declare any public methods that are not |
|
238 |
* declared in the {@link java.net.DatagramSocket} class. </p> |
|
239 |
* |
|
240 |
* @return A datagram socket associated with this channel |
|
241 |
*/ |
|
242 |
public abstract DatagramSocket socket(); |
|
243 |
||
244 |
/** |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
245 |
* Tells whether or not this channel's socket is connected. |
2 | 246 |
* |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
247 |
* @return {@code true} if, and only if, this channel's socket |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
248 |
* is {@link #isOpen open} and connected |
2 | 249 |
*/ |
250 |
public abstract boolean isConnected(); |
|
251 |
||
252 |
/** |
|
253 |
* Connects this channel's socket. |
|
254 |
* |
|
255 |
* <p> The channel's socket is configured so that it only receives |
|
256 |
* datagrams from, and sends datagrams to, the given remote <i>peer</i> |
|
257 |
* address. Once connected, datagrams may not be received from or sent to |
|
258 |
* any other address. A datagram socket remains connected until it is |
|
259 |
* explicitly disconnected or until it is closed. |
|
260 |
* |
|
261 |
* <p> This method performs exactly the same security checks as the {@link |
|
262 |
* java.net.DatagramSocket#connect connect} method of the {@link |
|
263 |
* java.net.DatagramSocket} class. That is, if a security manager has been |
|
264 |
* installed then this method verifies that its {@link |
|
265 |
* java.lang.SecurityManager#checkAccept checkAccept} and {@link |
|
266 |
* java.lang.SecurityManager#checkConnect checkConnect} methods permit |
|
267 |
* datagrams to be received from and sent to, respectively, the given |
|
58501
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
268 |
* remote address. Once connected, no further security checks are performed |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
269 |
* for datagrams received from, or sent to, the given remote address. Care |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
270 |
* should be taken to ensure that a connected datagram channel is not shared |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
271 |
* with untrusted code. |
2 | 272 |
* |
273 |
* <p> This method may be invoked at any time. It will not have any effect |
|
274 |
* on read or write operations that are already in progress at the moment |
|
2427
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
275 |
* that it is invoked. If this channel's socket is not bound then this method |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
276 |
* will first cause the socket to be bound to an address that is assigned |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
277 |
* automatically, as if invoking the {@link #bind bind} method with a |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
278 |
* parameter of {@code null}. </p> |
2 | 279 |
* |
280 |
* @param remote |
|
281 |
* The remote address to which this channel is to be connected |
|
282 |
* |
|
283 |
* @return This datagram channel |
|
284 |
* |
|
49284
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
285 |
* @throws AlreadyConnectedException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
286 |
* If this channel is already connected |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
287 |
* |
2 | 288 |
* @throws ClosedChannelException |
289 |
* If this channel is closed |
|
290 |
* |
|
291 |
* @throws AsynchronousCloseException |
|
292 |
* If another thread closes this channel |
|
293 |
* while the connect operation is in progress |
|
294 |
* |
|
295 |
* @throws ClosedByInterruptException |
|
296 |
* If another thread interrupts the current thread |
|
297 |
* while the connect operation is in progress, thereby |
|
298 |
* closing the channel and setting the current thread's |
|
299 |
* interrupt status |
|
300 |
* |
|
49284
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
301 |
* @throws UnresolvedAddressException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
302 |
* If the given remote address is not fully resolved |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
303 |
* |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
304 |
* @throws UnsupportedAddressTypeException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
305 |
* If the type of the given remote address is not supported |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
306 |
* |
2 | 307 |
* @throws SecurityException |
308 |
* If a security manager has been installed |
|
309 |
* and it does not permit access to the given remote address |
|
310 |
* |
|
311 |
* @throws IOException |
|
312 |
* If some other I/O error occurs |
|
313 |
*/ |
|
314 |
public abstract DatagramChannel connect(SocketAddress remote) |
|
315 |
throws IOException; |
|
316 |
||
317 |
/** |
|
318 |
* Disconnects this channel's socket. |
|
319 |
* |
|
320 |
* <p> The channel's socket is configured so that it can receive datagrams |
|
321 |
* from, and sends datagrams to, any remote address so long as the security |
|
322 |
* manager, if installed, permits it. |
|
323 |
* |
|
324 |
* <p> This method may be invoked at any time. It will not have any effect |
|
325 |
* on read or write operations that are already in progress at the moment |
|
326 |
* that it is invoked. |
|
327 |
* |
|
328 |
* <p> If this channel's socket is not connected, or if the channel is |
|
329 |
* closed, then invoking this method has no effect. </p> |
|
330 |
* |
|
58518
705c3f88a409
8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents:
58501
diff
changeset
|
331 |
* @apiNote If this method throws an IOException, the channel's socket |
705c3f88a409
8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents:
58501
diff
changeset
|
332 |
* may be left in an unspecified state. It is strongly recommended that |
705c3f88a409
8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents:
58501
diff
changeset
|
333 |
* the channel be closed when disconnect fails. |
705c3f88a409
8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents:
58501
diff
changeset
|
334 |
* |
2 | 335 |
* @return This datagram channel |
336 |
* |
|
337 |
* @throws IOException |
|
338 |
* If some other I/O error occurs |
|
339 |
*/ |
|
340 |
public abstract DatagramChannel disconnect() throws IOException; |
|
341 |
||
342 |
/** |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
343 |
* Returns the remote address to which this channel's socket is connected. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
344 |
* |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
345 |
* @return The remote address; {@code null} if the channel's socket is not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
346 |
* connected |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
347 |
* |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
348 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
349 |
* If the channel is closed |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
350 |
* @throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
351 |
* If an I/O error occurs |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
352 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
353 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
354 |
*/ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
355 |
public abstract SocketAddress getRemoteAddress() throws IOException; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
356 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
357 |
/** |
2 | 358 |
* Receives a datagram via this channel. |
359 |
* |
|
360 |
* <p> If a datagram is immediately available, or if this channel is in |
|
361 |
* blocking mode and one eventually becomes available, then the datagram is |
|
362 |
* copied into the given byte buffer and its source address is returned. |
|
363 |
* If this channel is in non-blocking mode and a datagram is not |
|
364 |
* immediately available then this method immediately returns |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
365 |
* {@code null}. |
2 | 366 |
* |
367 |
* <p> The datagram is transferred into the given byte buffer starting at |
|
368 |
* its current position, as if by a regular {@link |
|
369 |
* ReadableByteChannel#read(java.nio.ByteBuffer) read} operation. If there |
|
370 |
* are fewer bytes remaining in the buffer than are required to hold the |
|
371 |
* datagram then the remainder of the datagram is silently discarded. |
|
372 |
* |
|
373 |
* <p> This method performs exactly the same security checks as the {@link |
|
374 |
* java.net.DatagramSocket#receive receive} method of the {@link |
|
375 |
* java.net.DatagramSocket} class. That is, if the socket is not connected |
|
376 |
* to a specific remote address and a security manager has been installed |
|
377 |
* then for each datagram received this method verifies that the source's |
|
378 |
* address and port number are permitted by the security manager's {@link |
|
58501
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
379 |
* java.lang.SecurityManager#checkAccept checkAccept} method. Datagrams |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
380 |
* that are not permitted by the security manager are silently discarded. |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
381 |
* The overhead of this security check can be avoided by first connecting |
6fc4a729763e
8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents:
49284
diff
changeset
|
382 |
* the socket via the {@link #connect connect} method. |
2 | 383 |
* |
384 |
* <p> This method may be invoked at any time. If another thread has |
|
385 |
* already initiated a read operation upon this channel, however, then an |
|
386 |
* invocation of this method will block until the first operation is |
|
2427
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
387 |
* complete. If this channel's socket is not bound then this method will |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
388 |
* first cause the socket to be bound to an address that is assigned |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
389 |
* automatically, as if invoking the {@link #bind bind} method with a |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
390 |
* parameter of {@code null}. </p> |
2 | 391 |
* |
392 |
* @param dst |
|
393 |
* The buffer into which the datagram is to be transferred |
|
394 |
* |
|
395 |
* @return The datagram's source address, |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
396 |
* or {@code null} if this channel is in non-blocking mode |
2 | 397 |
* and no datagram was immediately available |
398 |
* |
|
399 |
* @throws ClosedChannelException |
|
400 |
* If this channel is closed |
|
401 |
* |
|
402 |
* @throws AsynchronousCloseException |
|
403 |
* If another thread closes this channel |
|
404 |
* while the read operation is in progress |
|
405 |
* |
|
406 |
* @throws ClosedByInterruptException |
|
407 |
* If another thread interrupts the current thread |
|
408 |
* while the read operation is in progress, thereby |
|
409 |
* closing the channel and setting the current thread's |
|
410 |
* interrupt status |
|
411 |
* |
|
412 |
* @throws IOException |
|
413 |
* If some other I/O error occurs |
|
414 |
*/ |
|
415 |
public abstract SocketAddress receive(ByteBuffer dst) throws IOException; |
|
416 |
||
417 |
/** |
|
418 |
* Sends a datagram via this channel. |
|
419 |
* |
|
420 |
* <p> If this channel is in non-blocking mode and there is sufficient room |
|
421 |
* in the underlying output buffer, or if this channel is in blocking mode |
|
422 |
* and sufficient room becomes available, then the remaining bytes in the |
|
423 |
* given buffer are transmitted as a single datagram to the given target |
|
424 |
* address. |
|
425 |
* |
|
426 |
* <p> The datagram is transferred from the byte buffer as if by a regular |
|
427 |
* {@link WritableByteChannel#write(java.nio.ByteBuffer) write} operation. |
|
428 |
* |
|
429 |
* <p> This method performs exactly the same security checks as the {@link |
|
430 |
* java.net.DatagramSocket#send send} method of the {@link |
|
431 |
* java.net.DatagramSocket} class. That is, if the socket is not connected |
|
432 |
* to a specific remote address and a security manager has been installed |
|
433 |
* then for each datagram sent this method verifies that the target address |
|
434 |
* and port number are permitted by the security manager's {@link |
|
435 |
* java.lang.SecurityManager#checkConnect checkConnect} method. The |
|
436 |
* overhead of this security check can be avoided by first connecting the |
|
437 |
* socket via the {@link #connect connect} method. |
|
438 |
* |
|
439 |
* <p> This method may be invoked at any time. If another thread has |
|
440 |
* already initiated a write operation upon this channel, however, then an |
|
441 |
* invocation of this method will block until the first operation is |
|
2427
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
442 |
* complete. If this channel's socket is not bound then this method will |
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
443 |
* first cause the socket to be bound to an address that is assigned |
3419 | 444 |
* automatically, as if by invoking the {@link #bind bind} method with a |
2427
f35f516befc3
6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents:
2057
diff
changeset
|
445 |
* parameter of {@code null}. </p> |
2 | 446 |
* |
447 |
* @param src |
|
448 |
* The buffer containing the datagram to be sent |
|
449 |
* |
|
450 |
* @param target |
|
451 |
* The address to which the datagram is to be sent |
|
452 |
* |
|
453 |
* @return The number of bytes sent, which will be either the number |
|
454 |
* of bytes that were remaining in the source buffer when this |
|
455 |
* method was invoked or, if this channel is non-blocking, may be |
|
456 |
* zero if there was insufficient room for the datagram in the |
|
457 |
* underlying output buffer |
|
458 |
* |
|
49284
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
459 |
* @throws AlreadyConnectedException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
460 |
* If this channel is connected to a different address |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
461 |
* from that specified by {@code target} |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
462 |
* |
2 | 463 |
* @throws ClosedChannelException |
464 |
* If this channel is closed |
|
465 |
* |
|
466 |
* @throws AsynchronousCloseException |
|
467 |
* If another thread closes this channel |
|
468 |
* while the read operation is in progress |
|
469 |
* |
|
470 |
* @throws ClosedByInterruptException |
|
471 |
* If another thread interrupts the current thread |
|
472 |
* while the read operation is in progress, thereby |
|
473 |
* closing the channel and setting the current thread's |
|
474 |
* interrupt status |
|
475 |
* |
|
49284
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
476 |
* @throws UnresolvedAddressException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
477 |
* If the given remote address is not fully resolved |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
478 |
* |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
479 |
* @throws UnsupportedAddressTypeException |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
480 |
* If the type of the given remote address is not supported |
a51ca91c2cde
8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents:
47216
diff
changeset
|
481 |
* |
2 | 482 |
* @throws SecurityException |
483 |
* If a security manager has been installed |
|
484 |
* and it does not permit datagrams to be sent |
|
485 |
* to the given address |
|
486 |
* |
|
487 |
* @throws IOException |
|
488 |
* If some other I/O error occurs |
|
489 |
*/ |
|
490 |
public abstract int send(ByteBuffer src, SocketAddress target) |
|
491 |
throws IOException; |
|
492 |
||
493 |
||
494 |
// -- ByteChannel operations -- |
|
495 |
||
496 |
/** |
|
497 |
* Reads a datagram from this channel. |
|
498 |
* |
|
499 |
* <p> This method may only be invoked if this channel's socket is |
|
500 |
* connected, and it only accepts datagrams from the socket's peer. If |
|
501 |
* there are more bytes in the datagram than remain in the given buffer |
|
502 |
* then the remainder of the datagram is silently discarded. Otherwise |
|
503 |
* this method behaves exactly as specified in the {@link |
|
504 |
* ReadableByteChannel} interface. </p> |
|
505 |
* |
|
506 |
* @throws NotYetConnectedException |
|
507 |
* If this channel's socket is not connected |
|
508 |
*/ |
|
509 |
public abstract int read(ByteBuffer dst) throws IOException; |
|
510 |
||
511 |
/** |
|
512 |
* Reads a datagram from this channel. |
|
513 |
* |
|
514 |
* <p> This method may only be invoked if this channel's socket is |
|
515 |
* connected, and it only accepts datagrams from the socket's peer. If |
|
516 |
* there are more bytes in the datagram than remain in the given buffers |
|
517 |
* then the remainder of the datagram is silently discarded. Otherwise |
|
518 |
* this method behaves exactly as specified in the {@link |
|
519 |
* ScatteringByteChannel} interface. </p> |
|
520 |
* |
|
521 |
* @throws NotYetConnectedException |
|
522 |
* If this channel's socket is not connected |
|
523 |
*/ |
|
524 |
public abstract long read(ByteBuffer[] dsts, int offset, int length) |
|
525 |
throws IOException; |
|
526 |
||
527 |
/** |
|
528 |
* Reads a datagram from this channel. |
|
529 |
* |
|
530 |
* <p> This method may only be invoked if this channel's socket is |
|
531 |
* connected, and it only accepts datagrams from the socket's peer. If |
|
532 |
* there are more bytes in the datagram than remain in the given buffers |
|
533 |
* then the remainder of the datagram is silently discarded. Otherwise |
|
534 |
* this method behaves exactly as specified in the {@link |
|
535 |
* ScatteringByteChannel} interface. </p> |
|
536 |
* |
|
537 |
* @throws NotYetConnectedException |
|
538 |
* If this channel's socket is not connected |
|
539 |
*/ |
|
540 |
public final long read(ByteBuffer[] dsts) throws IOException { |
|
541 |
return read(dsts, 0, dsts.length); |
|
542 |
} |
|
543 |
||
544 |
/** |
|
545 |
* Writes a datagram to this channel. |
|
546 |
* |
|
547 |
* <p> This method may only be invoked if this channel's socket is |
|
548 |
* connected, in which case it sends datagrams directly to the socket's |
|
549 |
* peer. Otherwise it behaves exactly as specified in the {@link |
|
550 |
* WritableByteChannel} interface. </p> |
|
551 |
* |
|
552 |
* @throws NotYetConnectedException |
|
553 |
* If this channel's socket is not connected |
|
554 |
*/ |
|
555 |
public abstract int write(ByteBuffer src) throws IOException; |
|
556 |
||
557 |
/** |
|
558 |
* Writes a datagram to this channel. |
|
559 |
* |
|
560 |
* <p> This method may only be invoked if this channel's socket is |
|
561 |
* connected, in which case it sends datagrams directly to the socket's |
|
562 |
* peer. Otherwise it behaves exactly as specified in the {@link |
|
563 |
* GatheringByteChannel} interface. </p> |
|
564 |
* |
|
565 |
* @return The number of bytes sent, which will be either the number |
|
566 |
* of bytes that were remaining in the source buffer when this |
|
567 |
* method was invoked or, if this channel is non-blocking, may be |
|
568 |
* zero if there was insufficient room for the datagram in the |
|
569 |
* underlying output buffer |
|
570 |
* |
|
571 |
* @throws NotYetConnectedException |
|
572 |
* If this channel's socket is not connected |
|
573 |
*/ |
|
574 |
public abstract long write(ByteBuffer[] srcs, int offset, int length) |
|
575 |
throws IOException; |
|
576 |
||
577 |
/** |
|
578 |
* Writes a datagram to this channel. |
|
579 |
* |
|
580 |
* <p> This method may only be invoked if this channel's socket is |
|
581 |
* connected, in which case it sends datagrams directly to the socket's |
|
582 |
* peer. Otherwise it behaves exactly as specified in the {@link |
|
583 |
* GatheringByteChannel} interface. </p> |
|
584 |
* |
|
585 |
* @return The number of bytes sent, which will be either the number |
|
586 |
* of bytes that were remaining in the source buffer when this |
|
587 |
* method was invoked or, if this channel is non-blocking, may be |
|
588 |
* zero if there was insufficient room for the datagram in the |
|
589 |
* underlying output buffer |
|
590 |
* |
|
591 |
* @throws NotYetConnectedException |
|
592 |
* If this channel's socket is not connected |
|
593 |
*/ |
|
594 |
public final long write(ByteBuffer[] srcs) throws IOException { |
|
595 |
return write(srcs, 0, srcs.length); |
|
596 |
} |
|
597 |
||
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
598 |
/** |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
599 |
* {@inheritDoc} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
600 |
* <p> |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
601 |
* If there is a security manager set, its {@code checkConnect} method is |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
602 |
* called with the local address and {@code -1} as its arguments to see |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
603 |
* if the operation is allowed. If the operation is not allowed, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
604 |
* a {@code SocketAddress} representing the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
605 |
* {@link java.net.InetAddress#getLoopbackAddress loopback} address and the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
606 |
* local port of the channel's socket is returned. |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
607 |
* |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
608 |
* @return The {@code SocketAddress} that the socket is bound to, or the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
609 |
* {@code SocketAddress} representing the loopback address if |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
610 |
* denied by the security manager, or {@code null} if the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
611 |
* channel's socket is not bound |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
612 |
* |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
613 |
* @throws ClosedChannelException {@inheritDoc} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
614 |
* @throws IOException {@inheritDoc} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
615 |
*/ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
616 |
@Override |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
617 |
public abstract SocketAddress getLocalAddress() throws IOException; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
618 |
|
2 | 619 |
} |