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
26 package java.nio.channels;
27
28 import java.io.IOException;
29 import java.net.ServerSocket;
30 import java.net.SocketOption;
31 import java.net.SocketAddress;
32 import java.nio.channels.spi.AbstractSelectableChannel;
33 import java.nio.channels.spi.SelectorProvider;
34
35 /**
36 * A selectable channel for stream-oriented listening sockets.
37 *
38 * <p> A server-socket channel is created by invoking the {@link #open() open}
39 * method of this class. It is not possible to create a channel for an arbitrary,
40 * pre-existing {@link ServerSocket}. A newly-created server-socket channel is
41 * open but not yet bound. An attempt to invoke the {@link #accept() accept}
42 * method of an unbound server-socket channel will cause a {@link NotYetBoundException}
43 * to be thrown. A server-socket channel can be bound by invoking one of the
44 * {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class.
45 *
46 * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
47 * setOption} method. Server-socket channels support the following options:
48 * <blockquote>
94 /**
95 * Opens a server-socket channel.
96 *
97 * <p> The new channel is created by invoking the {@link
98 * java.nio.channels.spi.SelectorProvider#openServerSocketChannel
99 * openServerSocketChannel} method of the system-wide default {@link
100 * java.nio.channels.spi.SelectorProvider} object.
101 *
102 * <p> The new channel's socket is initially unbound; it must be bound to a
103 * specific address via one of its socket's {@link
104 * java.net.ServerSocket#bind(SocketAddress) bind} methods before
105 * connections can be accepted. </p>
106 *
107 * @return A new socket channel
108 *
109 * @throws IOException
110 * If an I/O error occurs
111 */
112 public static ServerSocketChannel open() throws IOException {
113 return SelectorProvider.provider().openServerSocketChannel();
114 }
115
116 /**
117 * Returns an operation set identifying this channel's supported
118 * operations.
119 *
120 * <p> Server-socket channels only support the accepting of new
121 * connections, so this method returns {@link SelectionKey#OP_ACCEPT}.
122 * </p>
123 *
124 * @return The valid-operation set
125 */
126 public final int validOps() {
127 return SelectionKey.OP_ACCEPT;
128 }
129
130
131 // -- ServerSocket-specific operations --
132
133 /**
|
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
26 package java.nio.channels;
27
28 import java.io.IOException;
29 import java.net.ProtocolFamily;
30 import java.net.ServerSocket;
31 import java.net.SocketOption;
32 import java.net.SocketAddress;
33 import java.nio.channels.spi.AbstractSelectableChannel;
34 import java.nio.channels.spi.SelectorProvider;
35
36 /**
37 * A selectable channel for stream-oriented listening sockets.
38 *
39 * <p> A server-socket channel is created by invoking the {@link #open() open}
40 * method of this class. It is not possible to create a channel for an arbitrary,
41 * pre-existing {@link ServerSocket}. A newly-created server-socket channel is
42 * open but not yet bound. An attempt to invoke the {@link #accept() accept}
43 * method of an unbound server-socket channel will cause a {@link NotYetBoundException}
44 * to be thrown. A server-socket channel can be bound by invoking one of the
45 * {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class.
46 *
47 * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
48 * setOption} method. Server-socket channels support the following options:
49 * <blockquote>
95 /**
96 * Opens a server-socket channel.
97 *
98 * <p> The new channel is created by invoking the {@link
99 * java.nio.channels.spi.SelectorProvider#openServerSocketChannel
100 * openServerSocketChannel} method of the system-wide default {@link
101 * java.nio.channels.spi.SelectorProvider} object.
102 *
103 * <p> The new channel's socket is initially unbound; it must be bound to a
104 * specific address via one of its socket's {@link
105 * java.net.ServerSocket#bind(SocketAddress) bind} methods before
106 * connections can be accepted. </p>
107 *
108 * @return A new socket channel
109 *
110 * @throws IOException
111 * If an I/O error occurs
112 */
113 public static ServerSocketChannel open() throws IOException {
114 return SelectorProvider.provider().openServerSocketChannel();
115 }
116
117 /**
118 * Opens a server-socket for the specific address family.
119 *
120 * @see #open()
121 * @param family The protocol family e.g. AF_UNIX
122 * @return A new socket channel
123 * @throws IOException If an I/O error occurs
124 */
125 public static ServerSocketChannel open(ProtocolFamily family) throws IOException {
126 return SelectorProvider.provider().openServerSocketChannel(family);
127 }
128
129 /**
130 * Returns an operation set identifying this channel's supported
131 * operations.
132 *
133 * <p> Server-socket channels only support the accepting of new
134 * connections, so this method returns {@link SelectionKey#OP_ACCEPT}.
135 * </p>
136 *
137 * @return The valid-operation set
138 */
139 public final int validOps() {
140 return SelectionKey.OP_ACCEPT;
141 }
142
143
144 // -- ServerSocket-specific operations --
145
146 /**
|