This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: NIO stuff


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I committed the attached patch to trunk to make gnu.java.nio stuff 
cleaner.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+8CosWSOgCCdjSDsRAiDNAJwOLsUuIdCeBIkSDUxnI1bvxu87fACfTmmf
hGVnaUlLEjCRZunpi+tOevE=
=9VeS
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1958
diff -u -b -B -r1.1958 ChangeLog
--- ChangeLog	18 Jun 2003 08:15:42 -0000	1.1958
+++ ChangeLog	18 Jun 2003 08:55:28 -0000
@@ -1,5 +1,44 @@
 2003-06-18  Michael Koch  <konqueror@gmx.de>
 
+	* gnu/java/nio/SelectorImpl.java
+	(register): Use fd with value 0 for now, will be fixed later.
+	* gnu/java/nio/ServerSocketChannelImpl.java
+	(fd): Removed.
+	(local_port): Removed.
+	(InetSocketAddress): Removed.
+	(ServerSocketChannelImpl): Just initialize internal socket object.
+	(implCloseSelectableChannel): Close internal socket object.
+	(implConfigureBlocking): Added comment.
+	(accept): Use jaba.net stuff to accept socket.
+	* gnu/java/nio/SocketChannelImpl.java
+	(fd): Removed.
+	(local_port): Removed.
+	(InetSocketAddress): Removed.
+	(SocketCreate): Removed.
+	(SocketConnect): Removed.
+	(SocketBind): Removed.
+	(SocketListen): Removed.
+	(SocketAvailable): Removed.
+	(SocketClose): Removed.
+	(SocketRead): Removed.
+	(SocketWrite): Removed.
+	(SocketChannelImpl): Just initialize internal socket object.
+	(implCloseSelectableChannel): Close internal socket object.
+	(implConfigureBlocking): Fixed implementation, added comment.
+	(connect): Use internal socket object to connect.
+	(socket): No need for sanity checks.
+	(read): Comment out some stuff, this will be reimplemented in the next
+	commit.
+	(write): Likewise.
+	* gnu/java/nio/natFileChannelImpl.cc
+	(nio_mmap_file): Line wrapped.
+	* gnu/java/nio/natSocketChannelImpl.cc: Removed.
+	* Makefile.am
+	(nat_source_files): Removeded gnu/java/nio/natSocketChannelImpl.cc.
+	* Makefile.in: Regenerated.
+
+2003-06-18  Michael Koch  <konqueror@gmx.de>
+
 	* java/util/Locale.java
 	(equals): Merged from classpath.
 
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.298
diff -u -b -B -r1.298 Makefile.am
--- Makefile.am	11 Jun 2003 18:20:39 -0000	1.298
+++ Makefile.am	18 Jun 2003 08:55:31 -0000
@@ -2568,7 +2568,6 @@
 gnu/java/nio/natFileLockImpl.cc \
 gnu/java/nio/natMappedByteFileBuffer.cc \
 gnu/java/nio/natSelectorImpl.cc \
-gnu/java/nio/natSocketChannelImpl.cc \
 java/io/natFile.cc \
 java/io/natFileDescriptor.cc \
 java/io/natObjectInputStream.cc \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.322
diff -u -b -B -r1.322 Makefile.in
--- Makefile.in	11 Jun 2003 18:27:39 -0000	1.322
+++ Makefile.in	18 Jun 2003 08:55:36 -0000
@@ -2329,7 +2329,6 @@
 gnu/java/nio/natFileLockImpl.cc \
 gnu/java/nio/natMappedByteFileBuffer.cc \
 gnu/java/nio/natSelectorImpl.cc \
-gnu/java/nio/natSocketChannelImpl.cc \
 java/io/natFile.cc \
 java/io/natFileDescriptor.cc \
 java/io/natObjectInputStream.cc \
@@ -2503,13 +2502,13 @@
 gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \
 gnu/gcj/runtime/natVMClassLoader.lo gnu/java/nio/natFileChannelImpl.lo \
 gnu/java/nio/natFileLockImpl.lo gnu/java/nio/natMappedByteFileBuffer.lo \
-gnu/java/nio/natSelectorImpl.lo gnu/java/nio/natSocketChannelImpl.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/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 \
 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 \
@@ -2984,7 +2983,6 @@
 .deps/gnu/java/nio/natFileLockImpl.P \
 .deps/gnu/java/nio/natMappedByteFileBuffer.P \
 .deps/gnu/java/nio/natSelectorImpl.P \
-.deps/gnu/java/nio/natSocketChannelImpl.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/SelectorImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SelectorImpl.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 SelectorImpl.java
--- gnu/java/nio/SelectorImpl.java	14 Jun 2003 11:53:02 -0000	1.4
+++ gnu/java/nio/SelectorImpl.java	18 Jun 2003 08:55:36 -0000
@@ -255,17 +255,17 @@
     if (ch instanceof SocketChannelImpl)
       {
         SocketChannelImpl sc = (SocketChannelImpl) ch;
-        result = new SelectionKeyImpl (ch, this, sc.fd);
+        result = new SelectionKeyImpl (ch, this, 0); // FIXME: last argument
       }
     else if (ch instanceof DatagramChannelImpl)
       {
         DatagramChannelImpl dc = (DatagramChannelImpl) ch;
-        result = new SelectionKeyImpl (ch, this, dc.fd);
+        result = new SelectionKeyImpl (ch, this, 0); // FIXME: last argument
       }
     else if (ch instanceof ServerSocketChannelImpl)
       {
         ServerSocketChannelImpl ssc = (ServerSocketChannelImpl) ch;
-        result = new SelectionKeyImpl (ch, this, ssc.fd);
+        result = new SelectionKeyImpl (ch, this, 0); // FIXME: last argument
       }
     else
       {
Index: gnu/java/nio/ServerSocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/ServerSocketChannelImpl.java,v
retrieving revision 1.6
diff -u -b -B -r1.6 ServerSocketChannelImpl.java
--- gnu/java/nio/ServerSocketChannelImpl.java	14 Jun 2003 11:53:02 -0000	1.6
+++ gnu/java/nio/ServerSocketChannelImpl.java	18 Jun 2003 08:55:36 -0000
@@ -40,6 +41,7 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
+import java.net.Socket;
 import java.net.SocketAddress;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
@@ -48,27 +50,15 @@
 class ServerSocketChannelImpl extends ServerSocketChannel
 {
   ServerSocket serverSocket;
-  int fd;
-//   int local_port;
   boolean blocking = true;
   boolean connected = false;
-//   InetSocketAddress sa;
 
   protected ServerSocketChannelImpl (SelectorProvider provider)
     throws IOException
   {
     super (provider);
-    fd = SocketChannelImpl.SocketCreate ();
-
-    try
-      {
         serverSocket = new ServerSocket ();
       }
-    catch (IOException e)
-      {
-        System.err.println ("ServerSocket could not be created.");
-      }
-  }
  
   public void finalizer()
   {
@@ -87,20 +77,19 @@
   protected void implCloseSelectableChannel () throws IOException
   {
     connected = false;
-    SocketChannelImpl.SocketClose (fd);
-    fd = SocketChannelImpl.SocketCreate ();
+    serverSocket.close();
   }
 
   protected void implConfigureBlocking (boolean blocking) throws IOException
   {
-    this.blocking = blocking;
+    this.blocking = blocking; // FIXME
   }
 
   public SocketChannel accept () throws IOException
   {
     SocketChannelImpl result = new SocketChannelImpl (provider ());
-    result.sa = new InetSocketAddress (0);
-    //int res = SocketAccept (this,result);
+    Socket socket = serverSocket.accept();
+    //socket.setChannel (result); // FIXME
     return result;
   }
 
Index: gnu/java/nio/SocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SocketChannelImpl.java,v
retrieving revision 1.5
diff -u -b -B -r1.5 SocketChannelImpl.java
--- gnu/java/nio/SocketChannelImpl.java	14 Jun 2003 11:53:02 -0000	1.5
+++ gnu/java/nio/SocketChannelImpl.java	18 Jun 2003 08:55:36 -0000
@@ -52,30 +52,13 @@
 public class SocketChannelImpl extends SocketChannel
 {
   Socket socket;
-  int fd;
-  int local_port;
   boolean blocking = true;
   boolean connected = false;
-  InetSocketAddress sa;
 
-  static native int SocketCreate();
-  static native int SocketConnect(int fd, InetAddress addr, int port);
-  static native int SocketBind(int fd, InetAddress addr, int port);
-  static native int SocketListen(int fd, int backlog);
-  static native int SocketAvailable(int fd);
-  static native int SocketClose(int fd);
-  static native int SocketRead(int fd, byte b[], int off, int len);
-  static native int SocketWrite(int fd, byte b[], int off, int len);
-
-  public SocketChannelImpl(SelectorProvider provider)		      
-  {
-    super(provider);
-    fd = SocketCreate();
-	
-    if (fd == -1)
+  public SocketChannelImpl (SelectorProvider provider)		      
 	    {
-        System.err.println("failed to create socket:"+fd);
-	    }
+    super (provider);
+    socket = new Socket ();
   }
 
   public void finalizer()
@@ -95,39 +78,22 @@
   protected void implCloseSelectableChannel () throws IOException
   {
     connected = false;
-    SocketClose(fd);
-    fd = SocketCreate();
+    socket.close();
   }
 
   protected void implConfigureBlocking (boolean blocking) throws IOException
   {
-    if (this.blocking == blocking)
-      return;
+    this.blocking = blocking; // FIXME
   }   
 
   public boolean connect (SocketAddress remote) throws IOException
   {
     if (connected)
-      {
-        throw new AlreadyConnectedException ();
-      }
-
-    // ok, lets connect !
-	
-    sa = (InetSocketAddress) remote;
+      throw new AlreadyConnectedException();
 	
-    InetAddress addr = sa.getAddress();
-    int port = sa.getPort();
-    int err = SocketConnect(fd, addr, port);
-	
-    if (err < 0) 
-	    {
-        throw new IOException("Connection refused:"+err + ", connect="+err);
-	    }
-
-    local_port = err;
+    socket.connect (remote, 50);
     connected = true;
-    return blocking;
+    return blocking; // FIXME
   }
     
   public boolean finishConnect ()
@@ -147,11 +113,6 @@
     
   public Socket socket ()
   {
-    if (socket != null)
-	    {
-        //socket.ch = this;
-	    }
-
     return socket;
   }
 
@@ -161,6 +122,7 @@
     int len = 1024;
     byte[]b = new byte[len];
 	
+    /*
     bytes = SocketRead(fd, b, 0, len);
     dst.put(b, 0, bytes);
 
@@ -169,6 +131,7 @@
         // we've hit eof ?
         return -1;
       }
+    */
 
     return bytes;
   }
@@ -192,6 +155,7 @@
     int bytes = 0;
     int len = src.position();
 
+    /*
     if (src.hasArray ())
       {
         byte[] b = src.array ();
@@ -203,6 +167,7 @@
         src.get (b, 0, len);
         bytes = SocketWrite (fd, b, 0, len);
       }
+    */
 		
     return bytes;
   }
Index: gnu/java/nio/natFileChannelImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/natFileChannelImpl.cc,v
retrieving revision 1.5
diff -u -b -B -r1.5 natFileChannelImpl.cc
--- gnu/java/nio/natFileChannelImpl.cc	13 May 2003 09:13:31 -0000	1.5
+++ gnu/java/nio/natFileChannelImpl.cc	18 Jun 2003 08:55:36 -0000
@@ -73,7 +73,8 @@
 }
 
 gnu::gcj::RawData*
-gnu::java::nio::FileChannelImpl::nio_mmap_file (jlong pos, jlong size, jint /*mode*/)
+gnu::java::nio::FileChannelImpl::nio_mmap_file (jlong pos, jlong size,
+                                                jint /*mode*/)
 {
   throw new ::java::io::IOException (JvNewStringUTF ("mmap not implemented"));
 }
Index: gnu/java/nio/natSocketChannelImpl.cc
===================================================================
RCS file: gnu/java/nio/natSocketChannelImpl.cc
diff -N gnu/java/nio/natSocketChannelImpl.cc
--- gnu/java/nio/natSocketChannelImpl.cc	21 Feb 2003 08:19:34 -0000	1.4
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,172 +0,0 @@
-// natSocketChannelImpl.cc
-
-/* Copyright (C) 2002, 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 <gcj/cni.h>
-#include <gnu/java/nio/SocketChannelImpl.h>
-#include <java/io/IOException.h>
-#include <java/net/InetAddress.h>
-#include <java/net/SocketException.h>
-
-
-#ifdef DISABLE_JAVA_NET
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketCreate ()
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketCreate not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketConnect (jint,
-                                                  ::java::net::InetAddress *,
-                                                  jint)
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketConnect not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketBind (jint, ::java::net::InetAddress *,
-                                               jint)
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketBind not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketListen (jint, jint)
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketList not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketAvailable (jint)
-{
-  throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketClose (jint)
-{
-  throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketClose: not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketRead (jint, jbyteArray, jint, jint)
-{
-  throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketRead: not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketWrite (jint, jbyteArray, jint, jint)
-{
-  throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketWrite: not implemented"));
-}
-
-#else // DISABLE_JAVA_NET
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketCreate ()
-{
-  int sock = _Jv_socket (AF_INET, SOCK_STREAM, 0);
-
-  if (sock < 0)
-    {
-      char* strerr = strerror (errno);
-      throw new ::java::io::IOException (JvNewStringUTF (strerr));
-    }
-
-  return sock;
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketConnect (jint fd,
-                                                  ::java::net::InetAddress *addr,
-                                                  jint port)
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketConnect not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketBind (jint fd,
-                                               ::java::net::InetAddress *addr,
-                                               jint port)
-{
-  throw new ::java::io::IOException (JvNewStringUTF ("SocketBind not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketListen (jint fd, jint backlog)
-{
-  int result = _Jv_listen (fd, backlog);
-
-  if (result < 0)
-    {
-      char* strerr = strerror (errno);
-      throw new ::java::io::IOException (JvNewStringUTF (strerr));
-    }
-
-  return result;
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketAvailable (jint /*fd*/)
-{
-  throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketClose (jint fd)
-{
-  int result = _Jv_close (fd);
-
-  if (result < 0)
-    {
-      char* strerr = strerror (errno);
-      throw new ::java::io::IOException (JvNewStringUTF (strerr));
-    }
-
-  return result;
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketRead (jint fd, jbyteArray data,
-                                               jint offset, jint length)
-{
-  int result = ::recv (fd, data, offset, length);
-
-  if (result < 0)
-    {
-      char* strerr = strerror (errno);
-      throw new ::java::io::IOException (JvNewStringUTF (strerr));
-    }
-
-  return result;
-}
-
-jint
-gnu::java::nio::SocketChannelImpl::SocketWrite (jint fd, jbyteArray data,
-                                                jint offset, jint length)
-{
-  int result = ::send (fd, data, offset, length);
-
-  if (result < 0)
-    {
-      char* strerr = strerror (errno);
-      throw new ::java::io::IOException (JvNewStringUTF (strerr));
-    }
-
-  return result;
-}
-
-#endif // DISABLE_JAVA_NET

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]