summaryrefslogtreecommitdiffstats
path: root/libjava/gnu/java/nio/ServerSocketChannelImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/gnu/java/nio/ServerSocketChannelImpl.java')
-rw-r--r--libjava/gnu/java/nio/ServerSocketChannelImpl.java50
1 files changed, 32 insertions, 18 deletions
diff --git a/libjava/gnu/java/nio/ServerSocketChannelImpl.java b/libjava/gnu/java/nio/ServerSocketChannelImpl.java
index 3ee0ae0849b..89bbdec8746 100644
--- a/libjava/gnu/java/nio/ServerSocketChannelImpl.java
+++ b/libjava/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.
@@ -44,14 +44,17 @@ 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;
public final class ServerSocketChannelImpl extends ServerSocketChannel
{
- ServerSocket serverSocket;
- PlainSocketImpl impl;
+ NIOServerSocket serverSocket;
boolean blocking = true;
boolean connected = false;
@@ -59,20 +62,12 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
throws IOException
{
super (provider);
- impl = new PlainSocketImpl();
- initServerSocket();
+ serverSocket = new NIOServerSocket (this);
}
- /*
- * This method is only need to call a package private constructor
- * of java.net.ServerSocket. It only initializes the member variables
- * "serverSocket".
- */
- private native void initServerSocket() throws IOException;
-
public int getNativeFD()
{
- return impl.getNativeFD();
+ return serverSocket.getPlainSocketImpl().getNativeFD();
}
public void finalizer()
@@ -97,15 +92,34 @@ public final 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 ()
OpenPOWER on IntegriCloud