author | michaelm |
Thu, 14 Nov 2019 10:16:28 +0000 | |
branch | unixdomainchannels |
changeset 59076 | 998df1368cca |
parent 59074 | 7917f95f74c4 |
child 59078 | 4e648a2d8480 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, 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; |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
29 |
import java.net.ProtocolFamily; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
30 |
import java.net.StandardProtocolFamily; |
2 | 31 |
import java.net.ServerSocket; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
32 |
import java.net.SocketOption; |
2 | 33 |
import java.net.SocketAddress; |
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 stream-oriented listening sockets. |
|
39 |
* |
|
58981 | 40 |
* <p> A server-socket channel is created by invoking one of the open methods of this class. |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
41 |
* It is not possible to create a channel for an arbitrary, |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
42 |
* pre-existing {@link ServerSocket}. A newly-created server-socket channel is |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
43 |
* open but not yet bound. An attempt to invoke the {@link #accept() accept} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
44 |
* method of an unbound server-socket channel will cause a {@link NotYetBoundException} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
45 |
* to be thrown. A server-socket channel can be bound by invoking one of the |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
46 |
* {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class. |
2 | 47 |
* |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
48 |
* <p>Two kinds of server-socket channel are supported: <i>IP</i> (Internet Protocol) |
58981 | 49 |
* and <i>Unix Domain</i> depending on which open method is used to create them and which subtype of |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
50 |
* {@link SocketAddress} that they support for local and remote addresses. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
51 |
* <i>IP</i> channels are created using {@link #open()}. They use {@link |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
52 |
* InetSocketAddress} addresses and support both IPv4 and IPv6 TCP/IP. |
58981 | 53 |
* <i>Unix Domain</i> channels are created using {@link #open(ProtocolFamily)} |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
54 |
* with the family parameter set to {@link StandardProtocolFamily#UNIX}. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
55 |
* They use {@link UnixDomainSocketAddress}es and also |
59074 | 56 |
* do not support the {@link #socket()} method. Note, it is also possible to |
57 |
* create channels that support either IPv4 or IPv6 only through the |
|
58 |
* {@link #open(ProtocolFamily)} method. |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
59 |
* |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
60 |
* <p> Socket options are configured using the {@link #setOption(SocketOption,Object) |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
61 |
* setOption} method. <i>IP</i> server-socket channels support the following options: |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
62 |
* <blockquote> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
63 |
* <table class="striped"> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
64 |
* <caption style="display:none">Socket options</caption> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
65 |
* <thead> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
66 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
67 |
* <th scope="col">Option Name</th> |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
68 |
* <th scope="col">Description</th> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
69 |
* </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
70 |
* </thead> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
71 |
* <tbody> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
72 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
73 |
* <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
|
74 |
* <td> The size of the socket receive buffer </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
75 |
* </tr> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
76 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
77 |
* <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
|
78 |
* <td> Re-use address </td> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
79 |
* </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
32143
diff
changeset
|
80 |
* </tbody> |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
81 |
* </table> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
82 |
* </blockquote> |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
83 |
* |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
84 |
* Additional (implementation specific) options may also be supported. |
2 | 85 |
* |
86 |
* <p> Server-socket channels are safe for use by multiple concurrent threads. |
|
87 |
* </p> |
|
88 |
* |
|
58981 | 89 |
* <p><i>Unix Domain</i> server-socket channels support a subset of the options listed above. |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
90 |
* |
2 | 91 |
* @author Mark Reinhold |
92 |
* @author JSR-51 Expert Group |
|
93 |
* @since 1.4 |
|
94 |
*/ |
|
95 |
||
96 |
public abstract class ServerSocketChannel |
|
97 |
extends AbstractSelectableChannel |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
98 |
implements NetworkChannel |
2 | 99 |
{ |
100 |
||
101 |
/** |
|
102 |
* 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
|
103 |
* |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18212
diff
changeset
|
104 |
* @param provider |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18212
diff
changeset
|
105 |
* The provider that created this channel |
2 | 106 |
*/ |
107 |
protected ServerSocketChannel(SelectorProvider provider) { |
|
108 |
super(provider); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
112 |
* Opens an <i>IP</i> server-socket channel. |
2 | 113 |
* |
114 |
* <p> The new channel is created by invoking the {@link |
|
115 |
* java.nio.channels.spi.SelectorProvider#openServerSocketChannel |
|
116 |
* openServerSocketChannel} method of the system-wide default {@link |
|
117 |
* java.nio.channels.spi.SelectorProvider} object. |
|
118 |
* |
|
119 |
* <p> The new channel's socket is initially unbound; it must be bound to a |
|
120 |
* specific address via one of its socket's {@link |
|
121 |
* java.net.ServerSocket#bind(SocketAddress) bind} methods before |
|
122 |
* connections can be accepted. </p> |
|
123 |
* |
|
124 |
* @return A new socket channel |
|
125 |
* |
|
126 |
* @throws IOException |
|
127 |
* If an I/O error occurs |
|
128 |
*/ |
|
129 |
public static ServerSocketChannel open() throws IOException { |
|
130 |
return SelectorProvider.provider().openServerSocketChannel(); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
134 |
* Returns a {@link ServerSocketChannel} of the given protocol family. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
135 |
* Where family is equal to {@link StandardProtocolFamily#INET} or {@link |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
136 |
* StandardProtocolFamily#INET6} the returned channel must be bound to an |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
137 |
* {@link InetSocketAddress}. If family is {@link StandardProtocolFamily#UNIX} |
59074 | 138 |
* the returned channel must be bound to a {@link UnixDomainSocketAddress}. |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
139 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
140 |
* @param family the protocol family |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
141 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
142 |
* @return a ServerSocketChannel |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
143 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
144 |
* @throws IOException if an I/O error occurs |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
145 |
* @throws UnsupportedAddressTypeException if the protocol family is not supported |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
146 |
* @since 14 |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
147 |
*/ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
148 |
public static ServerSocketChannel open(ProtocolFamily family) throws IOException { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
149 |
return SelectorProvider.provider().openServerSocketChannel(family); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
150 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
151 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
152 |
/** |
2 | 153 |
* Returns an operation set identifying this channel's supported |
154 |
* operations. |
|
155 |
* |
|
156 |
* <p> Server-socket channels only support the accepting of new |
|
157 |
* connections, so this method returns {@link SelectionKey#OP_ACCEPT}. |
|
158 |
* </p> |
|
159 |
* |
|
160 |
* @return The valid-operation set |
|
161 |
*/ |
|
162 |
public final int validOps() { |
|
163 |
return SelectionKey.OP_ACCEPT; |
|
164 |
} |
|
165 |
||
166 |
||
167 |
// -- ServerSocket-specific operations -- |
|
168 |
||
169 |
/** |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
170 |
* Binds the channel's socket to a local address and configures the socket |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
171 |
* to listen for connections. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
172 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
173 |
* <p> An invocation of this method is equivalent to the following: |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
174 |
* <blockquote><pre> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
175 |
* bind(local, 0); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
176 |
* </pre></blockquote> |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
177 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
178 |
* @param local |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
179 |
* The local address to bind the socket, or {@code null} to bind |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
180 |
* to an automatically assigned socket address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
181 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
182 |
* @return This channel |
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 |
* @throws AlreadyBoundException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
185 |
* @throws UnsupportedAddressTypeException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
186 |
* @throws ClosedChannelException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
187 |
* @throws IOException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
188 |
* @throws SecurityException |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
189 |
* If a security manager has been installed and its |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
190 |
* {@link SecurityManager#checkListen checkListen} method denies |
58981 | 191 |
* the operation for <i>IP</i> channels. Or with <i>Unix Domain</i> |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
192 |
* channels, if the security manager denies "read" or "write" |
58847 | 193 |
* {@link java.io.FilePermission} for the local path. |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
194 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
195 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
196 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
197 |
public final ServerSocketChannel bind(SocketAddress local) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
198 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
199 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
200 |
return bind(local, 0); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
201 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
202 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
203 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
204 |
* Binds the channel's socket to a local address and configures the socket to |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
205 |
* listen for connections. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
206 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
207 |
* <p> This method is used to establish an association between the socket and |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
208 |
* a local address. Once an association is established then the socket remains |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
209 |
* bound until the channel is closed. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
210 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
211 |
* <p> The {@code backlog} parameter is the maximum number of pending |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
212 |
* connections on the socket. Its exact semantics are implementation specific. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
213 |
* In particular, an implementation may impose a maximum length or may choose |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
214 |
* to ignore the parameter altogther. If the {@code backlog} parameter has |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
215 |
* the value {@code 0}, or a negative value, then an implementation specific |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
216 |
* default is used. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
217 |
* |
58981 | 218 |
* <p> Note, for <i>Unix Domain</i> channels, a file is created in the file-system |
58847 | 219 |
* with the same path name as this channel's bound {@link UnixDomainSocketAddress}. |
220 |
* This file persists after the channel is closed, and must be removed before |
|
59076 | 221 |
* another channel can bind to the same name. Also, <i>Unix Domain</i> ServerSocketChannels |
222 |
* must be bound to an explicit address. |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
223 |
* |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
224 |
* @param local |
59076 | 225 |
* The address to bind the socket, or {@code null} to bind an <i>IP</i> channel to |
226 |
* an automatically assigned socket address |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
227 |
* @param backlog |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
228 |
* The maximum number of pending connections |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
229 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
230 |
* @return This channel |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
231 |
* |
59076 | 232 |
* @throws BindException |
233 |
* If this is a <i>Unix domain</i> channel and {@code local} is {@code null} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
234 |
* @throws AlreadyBoundException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
235 |
* If the socket is already bound |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
236 |
* @throws UnsupportedAddressTypeException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
237 |
* If the type of the given address is not supported |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
238 |
* @throws ClosedChannelException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
239 |
* If this channel is closed |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
240 |
* @throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
241 |
* If some other I/O error occurs |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
242 |
* @throws SecurityException |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
243 |
* If a security manager has been installed and its |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
244 |
* {@link SecurityManager#checkListen checkListen} method denies |
58981 | 245 |
* the operation for <i>IP</i> channels; or in the case of <i>Unix Domain</i> |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
246 |
* channels, if the security manager denies "read" or "write" |
58847 | 247 |
* {@link java.io.FilePermission} for the local path. |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
248 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
249 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
250 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
251 |
public abstract ServerSocketChannel bind(SocketAddress local, int backlog) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
252 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
253 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
254 |
/** |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
255 |
* @throws UnsupportedOperationException {@inheritDoc} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
256 |
* @throws IllegalArgumentException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
257 |
* @throws ClosedChannelException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
258 |
* @throws IOException {@inheritDoc} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
259 |
* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
260 |
* @since 1.7 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
261 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
262 |
public abstract <T> ServerSocketChannel setOption(SocketOption<T> name, T value) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
263 |
throws IOException; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
264 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
265 |
/** |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
266 |
* Retrieves a server socket associated with this channel if it is an <i>IP</i> |
58981 | 267 |
* channel. The operation is not supported for <i>Unix Domain</i> channels. |
2 | 268 |
* |
269 |
* <p> The returned object will not declare any public methods that are not |
|
270 |
* declared in the {@link java.net.ServerSocket} class. </p> |
|
271 |
* |
|
272 |
* @return A server socket associated with this channel |
|
58981 | 273 |
* |
274 |
* @throws UnsupportedOperationException if this is a Unix Domain channel |
|
2 | 275 |
*/ |
276 |
public abstract ServerSocket socket(); |
|
277 |
||
278 |
/** |
|
279 |
* Accepts a connection made to this channel's socket. |
|
280 |
* |
|
281 |
* <p> If this channel is in non-blocking mode then this method will |
|
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
282 |
* immediately return {@code null} if there are no pending connections. |
2 | 283 |
* Otherwise it will block indefinitely until a new connection is available |
284 |
* or an I/O error occurs. |
|
285 |
* |
|
286 |
* <p> The socket channel returned by this method, if any, will be in |
|
287 |
* blocking mode regardless of the blocking mode of this channel. |
|
288 |
* |
|
58847 | 289 |
* <p> For <i>IP</i> channels, this method performs exactly the same security checks |
290 |
* as the {@link java.net.ServerSocket#accept accept} method of the {@link |
|
2 | 291 |
* java.net.ServerSocket} class. That is, if a security manager has been |
292 |
* installed then for each new connection this method verifies that the |
|
293 |
* address and port number of the connection's remote endpoint are |
|
294 |
* permitted by the security manager's {@link |
|
295 |
* java.lang.SecurityManager#checkAccept checkAccept} method. </p> |
|
296 |
* |
|
58981 | 297 |
* <p> For <i>Unix Domain</i> channels, this method performs a security |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
298 |
* manager {@link SecurityManager#checkPermission(Permission)} using |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
299 |
* a {@link java.io.FilePermission} constructed with the path from the |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
300 |
* remote address and "read,write" as the actions. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
301 |
* |
2 | 302 |
* @return The socket channel for the new connection, |
32143
394ab6a6658d
8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents:
25859
diff
changeset
|
303 |
* or {@code null} if this channel is in non-blocking mode |
2 | 304 |
* and no connection is available to be accepted |
305 |
* |
|
306 |
* @throws ClosedChannelException |
|
307 |
* If this channel is closed |
|
308 |
* |
|
309 |
* @throws AsynchronousCloseException |
|
310 |
* If another thread closes this channel |
|
311 |
* while the accept operation is in progress |
|
312 |
* |
|
313 |
* @throws ClosedByInterruptException |
|
314 |
* If another thread interrupts the current thread |
|
315 |
* while the accept operation is in progress, thereby |
|
316 |
* closing the channel and setting the current thread's |
|
317 |
* interrupt status |
|
318 |
* |
|
319 |
* @throws NotYetBoundException |
|
320 |
* If this channel's socket has not yet been bound |
|
321 |
* |
|
322 |
* @throws SecurityException |
|
323 |
* If a security manager has been installed |
|
324 |
* and it does not permit access to the remote endpoint |
|
325 |
* of the new connection |
|
326 |
* |
|
327 |
* @throws IOException |
|
328 |
* If some other I/O error occurs |
|
329 |
*/ |
|
330 |
public abstract SocketChannel accept() throws IOException; |
|
331 |
||
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
332 |
/** |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
333 |
* {@inheritDoc} |
58981 | 334 |
* Where the channel is bound to a <i>Unix Domain</i> address, the return |
335 |
* value from this method is of type {@link UnixDomainSocketAddress}. |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
336 |
* <p> |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
337 |
* If there is a security manager set and this is an <i>IP</i> channel, |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
338 |
* {@code checkConnect} method is |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
339 |
* 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
|
340 |
* 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
|
341 |
* a {@code SocketAddress} representing the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
342 |
* {@link java.net.InetAddress#getLoopbackAddress loopback} address and the |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
343 |
* local port of the channel's socket is returned. |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
47216
diff
changeset
|
344 |
* <p> |
58981 | 345 |
* If there is a security manager set and this is a <i>Unix Domain</i> channel, |
58847 | 346 |
* then {@link SecurityManager#checkPermission(Permission)} is called using |
347 |
* a {@link java.io.FilePermission} constructed with the path from the |
|
348 |
* local address and "read" as the action. If this check fails |
|
349 |
* then an unnamed {@link UnixDomainSocketAddress} (with empty pathname) |
|
350 |
* is returned. |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
351 |
* |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
352 |
* @return The {@code SocketAddress} that the socket is bound to, or the |
58981 | 353 |
* {@code SocketAddress} representing the loopback address or empty |
354 |
* pathname if denied by the security manager, or {@code null} if the |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
355 |
* channel's socket is not bound |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
356 |
* |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
357 |
* @throws ClosedChannelException {@inheritDoc} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
358 |
* @throws IOException {@inheritDoc} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
359 |
*/ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
360 |
@Override |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
361 |
public abstract SocketAddress getLocalAddress() throws IOException; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
362 |
|
2 | 363 |
} |