From 137f5e8417ffa8ce2160bce1d45ce3b54ed16add Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Thu, 9 Oct 2003 18:01:08 +0000 Subject: [PATCH] SelectorImpl.java (register): Use ServerSocketChannelSelectionKey for server socket channels... 2003-10-09 Michael Koch * gnu/java/nio/SelectorImpl.java (register): Use ServerSocketChannelSelectionKey for server socket channels, removed unneeded comments. * gnu/java/nio/ServerSocketChannelImpl.java (ServerSocketChannelImpl): Made class public final. (impl): New member variable. (ServerSocketChannelImpl): Initialize member variables correctly. (initServerSocket): New method. (getNativeFD): Likewise. * gnu/java/nio/ServerSocketChannelSelectionKey.java, gnu/java/nio/natServerSocketChannelImpl.cc: New files. * Makefile.am (ordinary_java_source_files): Added gnu/java/nio/ServerSocketChannelSelectionKey.java. (nat_source_files): Added gnu/java/nio/natServerSocketChannelImpl.cc. * Makefile.in: Regenrated. From-SVN: r72277 --- libjava/ChangeLog | 18 ++++++ libjava/Makefile.am | 2 + libjava/Makefile.in | 17 ++++-- libjava/gnu/java/nio/SelectorImpl.java | 6 +- .../gnu/java/nio/ServerSocketChannelImpl.java | 19 ++++++- .../nio/ServerSocketChannelSelectionKey.java | 56 +++++++++++++++++++ .../java/nio/natServerSocketChannelImpl.cc | 25 +++++++++ 7 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 libjava/gnu/java/nio/ServerSocketChannelSelectionKey.java create mode 100644 libjava/gnu/java/nio/natServerSocketChannelImpl.cc diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 35238540e14..f652234fb45 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,21 @@ +2003-10-09 Michael Koch + + * gnu/java/nio/SelectorImpl.java (register): + Use ServerSocketChannelSelectionKey for server socket channels, + removed unneeded comments. + * gnu/java/nio/ServerSocketChannelImpl.java + (ServerSocketChannelImpl): Made class public final. + (impl): New member variable. + (ServerSocketChannelImpl): Initialize member variables correctly. + (initServerSocket): New method. + (getNativeFD): Likewise. + * gnu/java/nio/ServerSocketChannelSelectionKey.java, + gnu/java/nio/natServerSocketChannelImpl.cc: New files. + * Makefile.am (ordinary_java_source_files): + Added gnu/java/nio/ServerSocketChannelSelectionKey.java. + (nat_source_files): Added gnu/java/nio/natServerSocketChannelImpl.cc. + * Makefile.in: Regenrated. + 2003-10-09 Michael Koch * java/nio/channels/spi/AbstractSelectableChannel.java diff --git a/libjava/Makefile.am b/libjava/Makefile.am index 8160ec416b2..c2588eb2bb6 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -2193,6 +2193,7 @@ gnu/java/nio/SelectionKeyImpl.java \ gnu/java/nio/SelectorImpl.java \ gnu/java/nio/SelectorProviderImpl.java \ gnu/java/nio/ServerSocketChannelImpl.java \ +gnu/java/nio/ServerSocketChannelSelectionKey.java \ gnu/java/nio/SocketChannelImpl.java \ gnu/java/nio/SocketChannelSelectionKey.java \ gnu/java/nio/charset/ISO_8859_1.java \ @@ -2658,6 +2659,7 @@ gnu/java/net/natPlainSocketImpl.cc \ gnu/java/net/protocol/core/natCoreInputStream.cc \ gnu/java/nio/natFileLockImpl.cc \ gnu/java/nio/natSelectorImpl.cc \ +gnu/java/nio/natServerSocketChannelImpl.cc \ java/io/natFile.cc \ java/io/natFileDescriptor.cc \ java/io/natObjectInputStream.cc \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 3d2754c5eab..cbebfe6dbb1 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -1912,6 +1912,7 @@ gnu/java/nio/SelectionKeyImpl.java \ gnu/java/nio/SelectorImpl.java \ gnu/java/nio/SelectorProviderImpl.java \ gnu/java/nio/ServerSocketChannelImpl.java \ +gnu/java/nio/ServerSocketChannelSelectionKey.java \ gnu/java/nio/SocketChannelImpl.java \ gnu/java/nio/SocketChannelSelectionKey.java \ gnu/java/nio/charset/ISO_8859_1.java \ @@ -2376,6 +2377,7 @@ gnu/java/net/natPlainSocketImpl.cc \ gnu/java/net/protocol/core/natCoreInputStream.cc \ gnu/java/nio/natFileLockImpl.cc \ gnu/java/nio/natSelectorImpl.cc \ +gnu/java/nio/natServerSocketChannelImpl.cc \ java/io/natFile.cc \ java/io/natFileDescriptor.cc \ java/io/natObjectInputStream.cc \ @@ -2553,12 +2555,13 @@ gnu/java/net/natPlainDatagramSocketImpl.lo \ gnu/java/net/natPlainSocketImpl.lo \ gnu/java/net/protocol/core/natCoreInputStream.lo \ gnu/java/nio/natFileLockImpl.lo gnu/java/nio/natSelectorImpl.lo \ -java/io/natFile.lo java/io/natFileDescriptor.lo \ -java/io/natObjectInputStream.lo java/io/natVMObjectStreamClass.lo \ -java/lang/natCharacter.lo java/lang/natClass.lo \ -java/lang/natClassLoader.lo java/lang/natConcreteProcess.lo \ -java/lang/natDouble.lo java/lang/natFloat.lo java/lang/natMath.lo \ -java/lang/natObject.lo java/lang/natRuntime.lo java/lang/natString.lo \ +gnu/java/nio/natServerSocketChannelImpl.lo java/io/natFile.lo \ +java/io/natFileDescriptor.lo java/io/natObjectInputStream.lo \ +java/io/natVMObjectStreamClass.lo java/lang/natCharacter.lo \ +java/lang/natClass.lo java/lang/natClassLoader.lo \ +java/lang/natConcreteProcess.lo java/lang/natDouble.lo \ +java/lang/natFloat.lo java/lang/natMath.lo java/lang/natObject.lo \ +java/lang/natRuntime.lo java/lang/natString.lo \ java/lang/natStringBuffer.lo java/lang/natSystem.lo \ java/lang/natThread.lo java/lang/natVMSecurityManager.lo \ java/lang/ref/natReference.lo java/lang/reflect/natArray.lo \ @@ -3037,6 +3040,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/java/nio/SelectorImpl.P \ .deps/gnu/java/nio/SelectorProviderImpl.P \ .deps/gnu/java/nio/ServerSocketChannelImpl.P \ +.deps/gnu/java/nio/ServerSocketChannelSelectionKey.P \ .deps/gnu/java/nio/SocketChannelImpl.P \ .deps/gnu/java/nio/SocketChannelSelectionKey.P \ .deps/gnu/java/nio/charset/ISO_8859_1.P \ @@ -3049,6 +3053,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/java/nio/charset/UTF_16LE.P \ .deps/gnu/java/nio/charset/UTF_8.P .deps/gnu/java/nio/natFileLockImpl.P \ .deps/gnu/java/nio/natSelectorImpl.P \ +.deps/gnu/java/nio/natServerSocketChannelImpl.P \ .deps/gnu/java/rmi/RMIMarshalledObjectInputStream.P \ .deps/gnu/java/rmi/RMIMarshalledObjectOutputStream.P \ .deps/gnu/java/rmi/dgc/DGCImpl.P .deps/gnu/java/rmi/dgc/DGCImpl_Skel.P \ diff --git a/libjava/gnu/java/nio/SelectorImpl.java b/libjava/gnu/java/nio/SelectorImpl.java index 08531ef449a..60a81f98458 100644 --- a/libjava/gnu/java/nio/SelectorImpl.java +++ b/libjava/gnu/java/nio/SelectorImpl.java @@ -253,17 +253,17 @@ public class SelectorImpl extends AbstractSelector if (ch instanceof SocketChannelImpl) { SocketChannelImpl sc = (SocketChannelImpl) ch; - result = new SocketChannelSelectionKey (ch, this); // FIXME: last argument + result = new SocketChannelSelectionKey (ch, this); } else if (ch instanceof DatagramChannelImpl) { DatagramChannelImpl dc = (DatagramChannelImpl) ch; - result = new DatagramChannelSelectionKey (ch, this); // FIXME: last argument + result = new DatagramChannelSelectionKey (ch, this); } else if (ch instanceof ServerSocketChannelImpl) { ServerSocketChannelImpl ssc = (ServerSocketChannelImpl) ch; - result = new SocketChannelSelectionKey (ch, this); // FIXME: last argument + result = new ServerSocketChannelSelectionKey (ch, this); } else { diff --git a/libjava/gnu/java/nio/ServerSocketChannelImpl.java b/libjava/gnu/java/nio/ServerSocketChannelImpl.java index 05ad0aefc30..3ee0ae0849b 100644 --- a/libjava/gnu/java/nio/ServerSocketChannelImpl.java +++ b/libjava/gnu/java/nio/ServerSocketChannelImpl.java @@ -38,6 +38,7 @@ 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; @@ -47,9 +48,10 @@ 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; + PlainSocketImpl impl; boolean blocking = true; boolean connected = false; @@ -57,7 +59,20 @@ class ServerSocketChannelImpl extends ServerSocketChannel throws IOException { super (provider); - serverSocket = new ServerSocket (); + impl = new PlainSocketImpl(); + initServerSocket(); + } + + /* + * 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(); } public void finalizer() diff --git a/libjava/gnu/java/nio/ServerSocketChannelSelectionKey.java b/libjava/gnu/java/nio/ServerSocketChannelSelectionKey.java new file mode 100644 index 00000000000..55847e49a26 --- /dev/null +++ b/libjava/gnu/java/nio/ServerSocketChannelSelectionKey.java @@ -0,0 +1,56 @@ +/* ServerSocketChannelSelectionKey.java -- + Copyright (C) 2003 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.nio; + +import java.nio.channels.spi.AbstractSelectableChannel; + +public final class ServerSocketChannelSelectionKey + extends SelectionKeyImpl +{ + public ServerSocketChannelSelectionKey (AbstractSelectableChannel channel, + SelectorImpl selector) + { + super (channel, selector); + } + + public int getNativeFD() + { + return ((ServerSocketChannelImpl) ch).getNativeFD(); + } +} diff --git a/libjava/gnu/java/nio/natServerSocketChannelImpl.cc b/libjava/gnu/java/nio/natServerSocketChannelImpl.cc new file mode 100644 index 00000000000..a4b1ba4df01 --- /dev/null +++ b/libjava/gnu/java/nio/natServerSocketChannelImpl.cc @@ -0,0 +1,25 @@ +// natServerSocketChannelImpl.cc + +/* Copyright (C) 2003 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include +#include + +#include +#include + +#include +#include +#include + +void +gnu::java::nio::ServerSocketChannelImpl::initServerSocket() +{ + serverSocket = new ::java::net::ServerSocket (impl); +} -- 2.30.2