This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Patch: Java NIO
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 12 Oct 2003 15:44:46 +0200
- Subject: FYI: Patch: Java NIO
Hi list,
I commited a patch to provide more NIO functionality. Hopefully all slowly
begins to really work.
Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2258
diff -u -b -B -r1.2258 ChangeLog
--- ChangeLog 12 Oct 2003 13:33:30 -0000 1.2258
+++ ChangeLog 12 Oct 2003 13:38:39 -0000
@@ -1,5 +1,27 @@
2003-10-12 Michael Koch <konqueror@gmx.de>
+ * gnu/java/nio/PipeImpl.java
+ (SourceChannelImpl): New inner class.
+ (SinkChannelImpl): New inner class.
+ (sink): New member variable.
+ (source): New member variable.
+ (PipeImpl): Add SelectorProvider argument, implemented.
+ (nativeInit): New method.
+ (sink): Return sink channel.
+ (source): Return source channel.
+ * gnu/java/nio/SelectorProviderImpl.java
+ (openPipe): Give provider as argument to PipeImpl constructor.
+ * java/nio/channels/spi/SelectorProvider.java
+ (pr): Removed.
+ (systemDefaultProvider): New member variable.
+ (provider): Made it synchronized, use property
+ java.nio.channels.spi.SelectorProvider.
+ * gnu/java/nio/natPipeImpl.cc: New file.
+ * Makefile.am (nat_source_files): Added gnu/java/nio/natPipeImpl.cc.
+ * Makefile.in: Regenerated.
+
+2003-10-12 Michael Koch <konqueror@gmx.de>
+
* javax/swing/table/DefaultTableModel.java,
javax/swing/table/TableCellEditor.java,
javax/swing/table/TableCellRenderer.java,
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.331
diff -u -b -B -r1.331 Makefile.am
--- Makefile.am 11 Oct 2003 18:01:34 -0000 1.331
+++ Makefile.am 12 Oct 2003 13:38:41 -0000
@@ -2659,6 +2659,7 @@
gnu/java/net/natPlainSocketImpl.cc \
gnu/java/net/protocol/core/natCoreInputStream.cc \
gnu/java/nio/natFileLockImpl.cc \
+gnu/java/nio/natPipeImpl.cc \
gnu/java/nio/natSelectorImpl.cc \
gnu/java/nio/natNIOServerSocket.cc \
java/io/natFile.cc \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.355
diff -u -b -B -r1.355 Makefile.in
--- Makefile.in 11 Oct 2003 18:01:34 -0000 1.355
+++ Makefile.in 12 Oct 2003 13:38:44 -0000
@@ -2377,6 +2377,7 @@
gnu/java/net/natPlainSocketImpl.cc \
gnu/java/net/protocol/core/natCoreInputStream.cc \
gnu/java/nio/natFileLockImpl.cc \
+gnu/java/nio/natPipeImpl.cc \
gnu/java/nio/natSelectorImpl.cc \
gnu/java/nio/natNIOServerSocket.cc \
java/io/natFile.cc \
@@ -2555,14 +2556,14 @@
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 \
-gnu/java/nio/natNIOServerSocket.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/natFileLockImpl.lo gnu/java/nio/natPipeImpl.lo \
+gnu/java/nio/natSelectorImpl.lo gnu/java/nio/natNIOServerSocket.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 \
@@ -3055,7 +3056,7 @@
.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/natNIOServerSocket.P \
-.deps/gnu/java/nio/natSelectorImpl.P \
+.deps/gnu/java/nio/natPipeImpl.P .deps/gnu/java/nio/natSelectorImpl.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 \
Index: gnu/java/nio/PipeImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/PipeImpl.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 PipeImpl.java
--- gnu/java/nio/PipeImpl.java 18 Nov 2002 13:56:58 -0000 1.1
+++ gnu/java/nio/PipeImpl.java 12 Oct 2003 13:38:44 -0000
@@ -1,5 +1,5 @@
/* PipeImpl.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,21 +37,127 @@
package gnu.java.nio;
+import java.io.IOException;
+import java.nio.ByteBuffer;
import java.nio.channels.Pipe;
+import java.nio.channels.spi.SelectorProvider;
class PipeImpl extends Pipe
{
- public PipeImpl()
+ public final class SourceChannelImpl extends Pipe.SourceChannel
{
+ private int native_fd;
+
+ public SourceChannelImpl (SelectorProvider selectorProvider,
+ int native_fd)
+ {
+ super (selectorProvider);
+ this.native_fd = native_fd;
+ }
+
+ protected final void implCloseSelectableChannel()
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ protected void implConfigureBlocking (boolean blocking)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final int read (ByteBuffer src)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final long read (ByteBuffer[] srcs)
+ throws IOException
+ {
+ return read (srcs, 0, srcs.length);
+ }
+
+ public final long read (ByteBuffer[] srcs, int offset, int len)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final int getNativeFD()
+ {
+ return native_fd;
+ }
+ }
+
+ public final class SinkChannelImpl extends Pipe.SinkChannel
+ {
+ private int native_fd;
+
+ public SinkChannelImpl (SelectorProvider selectorProvider,
+ int native_fd)
+ {
+ super (selectorProvider);
+ this.native_fd = native_fd;
+ }
+
+ protected final void implCloseSelectableChannel()
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ protected final void implConfigureBlocking (boolean blocking)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final int write (ByteBuffer dst)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final long write (ByteBuffer[] dsts)
+ throws IOException
+ {
+ return write (dsts, 0, dsts.length);
}
+ public final long write (ByteBuffer[] dsts, int offset, int len)
+ throws IOException
+ {
+ throw new Error ("Not implemented");
+ }
+
+ public final int getNativeFD()
+ {
+ return native_fd;
+ }
+ }
+
+ private SinkChannelImpl sink;
+ private SourceChannelImpl source;
+
+ public PipeImpl (SelectorProvider provider)
+ throws IOException
+ {
+ super();
+ nativeInit (provider);
+ }
+
+ private native void nativeInit (SelectorProvider provider)
+ throws IOException;
+
public Pipe.SinkChannel sink()
{
- return null;
+ return sink;
}
public Pipe.SourceChannel source()
{
- return null;
+ return source;
}
}
Index: gnu/java/nio/SelectorProviderImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SelectorProviderImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 SelectorProviderImpl.java
--- gnu/java/nio/SelectorProviderImpl.java 11 Feb 2003 09:44:57 -0000 1.2
+++ gnu/java/nio/SelectorProviderImpl.java 12 Oct 2003 13:38:44 -0000
@@ -1,5 +1,5 @@
/* SelectorProviderImpl.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -60,7 +60,7 @@
public Pipe openPipe ()
throws IOException
{
- return new PipeImpl ();
+ return new PipeImpl (this);
}
public AbstractSelector openSelector ()
Index: gnu/java/nio/natPipeImpl.cc
===================================================================
RCS file: gnu/java/nio/natPipeImpl.cc
diff -N gnu/java/nio/natPipeImpl.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/natPipeImpl.cc 12 Oct 2003 13:38:44 -0000
@@ -0,0 +1,38 @@
+// natPipeImpl.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 <config.h>
+#include <platform.h>
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <gnu/java/nio/PipeImpl.h>
+//#include <gnu/java/nio/PipeImpl$SinkChannelImpl.h>
+//#include <gnu/java/nio/PipeImpl$SourceChannelImpl.h>
+#include <java/io/IOException.h>
+#include <java/nio/channels/spi/SelectorProvider.h>
+
+void
+gnu::java::nio::PipeImpl::nativeInit (::java::nio::channels::spi::SelectorProvider* /*provider*/)
+{
+ int filedes [2];
+
+ if (::pipe (filedes) < 0)
+ throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
+
+ /* FIXME
+ source = new gnu::java::nio::PipeImpl$SourceChannelImpl
+ (this, provider, filedes [0]);
+ sink = new gnu::java::nio::PipeImpl$SinkChannelImpl
+ (this, provider, filedes [1]);
+ */
+}
Index: java/nio/channels/spi/SelectorProvider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/SelectorProvider.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 SelectorProvider.java
--- java/nio/channels/spi/SelectorProvider.java 18 Feb 2003 07:26:20 -0000 1.4
+++ java/nio/channels/spi/SelectorProvider.java 12 Oct 2003 13:38:44 -0000
@@ -1,5 +1,5 @@
/* SelectorProvider.java
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,7 +50,7 @@
*/
public abstract class SelectorProvider
{
- static SelectorProvider pr;
+ private static SelectorProvider systemDefaultProvider;
/**
* Initializes the selector provider.
@@ -95,13 +95,32 @@
* Returns the system-wide default selector provider for this invocation
* of the Java virtual machine.
*/
- public static SelectorProvider provider ()
+ public static synchronized SelectorProvider provider ()
{
- if (pr == null)
+ if (systemDefaultProvider == null)
{
- pr = new SelectorProviderImpl ();
+ String propertyValue =
+ System.getProperty ("java.nio.channels.spi.SelectorProvider");
+
+ if (propertyValue == null
+ || propertyValue.equals (""))
+ systemDefaultProvider = new SelectorProviderImpl();
+ else
+ {
+ try
+ {
+ systemDefaultProvider = (SelectorProvider) Class.forName
+ (propertyValue).newInstance();
+ }
+ catch (Exception e)
+ {
+ System.err.println ("Could not instantiate class: "
+ + propertyValue);
+ systemDefaultProvider = new SelectorProviderImpl();
+ }
+ }
}
- return pr;
+ return systemDefaultProvider;
}
}