NIOSocket.java (setChannel): Initialize impl.
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. From-SVN: r72345
This commit is contained in:
parent
5a2a057de8
commit
51914674f4
9 changed files with 224 additions and 51 deletions
|
@ -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 ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue