summaryrefslogtreecommitdiffstats
path: root/libjava/gnu/java/nio/ServerSocketChannelImpl.java
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-11 18:01:35 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-11 18:01:35 +0000
commite95addcda5341dfee5599f8347c30f58ae3a8be6 (patch)
treef3c9f1f5921233e31d10682889fd919d402a47e7 /libjava/gnu/java/nio/ServerSocketChannelImpl.java
parent88a78d982ea6dc0ca6049e836a1fb17c489dc877 (diff)
downloadppe42-gcc-e95addcda5341dfee5599f8347c30f58ae3a8be6.tar.gz
ppe42-gcc-e95addcda5341dfee5599f8347c30f58ae3a8be6.zip
2003-10-11 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/NIOSocket.java (setChannel): Initialize impl. * gnu/java/nio/ServerSocketChannelImpl.java (serverSocket): Made it a NIOServerSocket. (impl): Removed. (ServerSocketChannelImpl): Initialize only serverSocket. (initServerSocket): Removed. (getNativeFD): Rewritten. (implConfigureBlocking): Set socket timeout and removed comment. (accept): Rewritten. * gnu/java/nio/SocketChannelImpl.java (impl): New variable. (connected): Removed. (SocketChannelImpl): Initialize impl too. (getImpl): New method. (isConnected): Rewritten. (read): Rewritten, set position in buffer correctly. (write): Set position in buffer correctly. * java/net/ServerSocket.java (getImpl): New method. * gnu/java/nio/NIOServerSocket.java, gnu/java/nio/natNIOServerSocket.cc: New files. * gnu/java/nio/natServerSocketChannelImpl.cc: Removed. * Makefile.am (ordinary_java_source_files): Added gnu/java/nio/NIOServerSocket.java. (nat_source_files): Removed gnu/java/nio/natServerSocketChannelImpl.cc and added gnu/java/nio/natNIOServerSocket.cc. * Makefile.in: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72345 138bc75d-0d04-0410-961f-82ee72b054a4
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