diff options
| author | Michael Koch <konqueror@gmx.de> | 2003-10-15 12:51:30 +0000 |
|---|---|---|
| committer | Michael Koch <konqueror@gmx.de> | 2003-10-15 12:51:30 +0000 |
| commit | 2096ba496342aa3318a3e7d40cb8d0732ba9ad67 (patch) | |
| tree | d02892e7f72d1366955cf983bce78d70a8ca4c0f /gnu/java/nio/ServerSocketChannelImpl.java | |
| parent | 10e8cffabc2540577202a4663f4737fc18cbb80f (diff) | |
| download | classpath-2096ba496342aa3318a3e7d40cb8d0732ba9ad67.tar.gz | |
2003-10-15 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/NIOSocket.java
(setChannel): Initialize impl.
* gnu/java/nio/ServerSocketChannelImpl.java
(ServerSocketChannelImpl): Made class public final.
(serverSocket): Made it a NIOServerSocket.
(getNativeFD): New method.
(implConfigureBlocking): Set socket timeout.
(accept): Rewritten.
* gnu/java/nio/SelectorImpl.java
(register): Use ServerSocketChannelSelectionKey for server socket
channels, removed comments.
* gnu/java/nio/SocketChannelImpl.java
(impl): New member variable.
(SocketChannelImpl): Initialize impl.
(getImpl): New method.
* gnu/java/nio/NIOServerSocket.java,
gnu/java/nio/ServerSocketChannelSelectionKey.java: New files.
* gnu/java/nio/Makefile.am (EXTRA_DIST):
Added NIOServerSocket.java and ServerSocketChannelSelectionKey.java.
Diffstat (limited to 'gnu/java/nio/ServerSocketChannelImpl.java')
| -rw-r--r-- | gnu/java/nio/ServerSocketChannelImpl.java | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/gnu/java/nio/ServerSocketChannelImpl.java b/gnu/java/nio/ServerSocketChannelImpl.java index 05ad0aefc..89bbdec87 100644 --- a/gnu/java/nio/ServerSocketChannelImpl.java +++ b/gnu/java/nio/ServerSocketChannelImpl.java @@ -1,5 +1,5 @@ /* ServerSocketChannelImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,18 +38,23 @@ exception statement from your version. */ package gnu.java.nio; +import gnu.java.net.PlainSocketImpl; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.NotYetBoundException; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; -class ServerSocketChannelImpl extends ServerSocketChannel +public final class ServerSocketChannelImpl extends ServerSocketChannel { - ServerSocket serverSocket; + NIOServerSocket serverSocket; boolean blocking = true; boolean connected = false; @@ -57,7 +62,12 @@ class ServerSocketChannelImpl extends ServerSocketChannel throws IOException { super (provider); - serverSocket = new ServerSocket (); + serverSocket = new NIOServerSocket (this); + } + + public int getNativeFD() + { + return serverSocket.getPlainSocketImpl().getNativeFD(); } public void finalizer() @@ -82,15 +92,34 @@ class ServerSocketChannelImpl extends ServerSocketChannel protected void implConfigureBlocking (boolean blocking) throws IOException { - this.blocking = blocking; // FIXME + serverSocket.setSoTimeout (blocking ? 0 : NIOConstants.DEFAULT_TIMEOUT); + this.blocking = blocking; } public SocketChannel accept () throws IOException { - SocketChannelImpl result = new SocketChannelImpl (provider ()); - Socket socket = serverSocket.accept(); - //socket.setChannel (result); // FIXME - return result; + if (!isOpen()) + throw new ClosedChannelException(); + + if (!serverSocket.isBound()) + throw new NotYetBoundException(); + + boolean completed = false; + + try + { + NIOSocket socket = (NIOSocket) serverSocket.accept(); + completed = true; + return socket.getChannel(); + } + catch (SocketTimeoutException e) + { + return null; + } + finally + { + end (completed); + } } public ServerSocket socket () |
