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: gnu.java.nio - socket channel stuff


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

Hi list,


I commited the attached patch which makes socket channels more 
working.


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

iD8DBQE+8ejBWSOgCCdjSDsRAukbAJ9G0Q//BbqXkoTJvEx6LRAzAiclqwCglId7
1FsUWjALRewrfnQz7AuXwZc=
=hxs5
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1969
diff -u -b -B -r1.1969 ChangeLog
--- ChangeLog	19 Jun 2003 16:30:08 -0000	1.1969
+++ ChangeLog	19 Jun 2003 16:36:35 -0000
@@ -1,5 +1,26 @@
 2003-06-19  Michael Koch  <konqueror@gmx.de>
 
+	* gnu/java/nio/DatagramChannelImpl.java
+	(fd): Removed.
+	(blocking): New member variable.
+	(socket): Likewise.
+	(DatagramChannelImpl): Throws IOException, initialize socket.
+	(socket):Implemented.
+	(implCloseSelectableChannel): Throws IOException, implemented.
+	(implConfigureBlocking): Likewise.
+	(connect): Likewise.
+	(disconnect): Likewise.
+	(isConnected): Likewise.
+	(write): Likewise.
+	(read): Likewise.
+	(receive): Throws IOException.
+	(send): Likewise.
+	* gnu/java/nio/SocketChannelImpl.java
+	(read): Implemented.
+	(write): Implemented.
+
+2003-06-19  Michael Koch  <konqueror@gmx.de>
+
 	* javax/swing/JComponent.java,
 	javax/swing/JInternalFrame.java,
 	javax/swing/MenuSelectionManager.java,
Index: gnu/java/nio/DatagramChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/DatagramChannelImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 DatagramChannelImpl.java
--- gnu/java/nio/DatagramChannelImpl.java	29 Nov 2002 09:57:05 -0000	1.2
+++ gnu/java/nio/DatagramChannelImpl.java	19 Jun 2003 16:36:35 -0000
@@ -35,78 +35,120 @@
 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.io.IOException;
 import java.net.DatagramSocket;
 import java.net.SocketAddress;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
+import java.nio.channels.NotYetConnectedException;
 import java.nio.channels.spi.SelectorProvider;
 
 public class DatagramChannelImpl extends DatagramChannel
 {
-  int fd;
+  boolean blocking = false;
+  DatagramSocket socket;
 
   protected DatagramChannelImpl (SelectorProvider provider)
+    throws IOException
   {
     super (provider);
+    socket = new DatagramSocket ();
+  }
+    
+  public DatagramSocket socket ()
+  {
+    return socket;
   }
     
   protected void implCloseSelectableChannel ()
+    throws IOException
   {
+    socket.close ();
   }
     
-  protected void implConfigureBlocking (boolean block)
+  protected void implConfigureBlocking (boolean blocking)
+    throws IOException
   {
+    this.blocking = blocking; // FIXME
   }
 
-  public int write (ByteBuffer src)
+  public DatagramChannel connect (SocketAddress remote)
+    throws IOException
   {
-    return 0;
+    socket.connect (remote);
+    return this;
   }
 
-  public long write (ByteBuffer[] srcs, int offset, int length)
+  public DatagramChannel disconnect ()
+    throws IOException
   {
-    return 0;
+    socket.disconnect ();
+    return this;
   }
 
-  public int read (ByteBuffer dst)
+  public boolean isConnected ()
   {
-    return 0;
+    return socket.isConnected ();
   }
     
-  public DatagramChannel connect (SocketAddress remote)
+  public int write (ByteBuffer src)
+    throws IOException
   {
-    return null;
+    if (!isConnected ())
+      throw new NotYetConnectedException ();
+    
+    throw new Error ("Not implemented");
   }
     
-  public DatagramChannel disconnect ()
+  public long write (ByteBuffer[] srcs, int offset, int length)
+    throws IOException
   {
-    return null;
+    // FIXME: Should we throw an exception if offset and/or length
+    // have wrong values ?
+
+    long result = 0;
+
+    for (int i = offset; i < offset + length; i++)
+      result += write (srcs [i]);
+
+    return result;
   }
     
-  public boolean isConnected ()
+  public int read (ByteBuffer dst)
+    throws IOException
   {
-    return false;
+    if (!isConnected ())
+      throw new NotYetConnectedException ();
+    
+    throw new Error ("Not implemented");
   }
     
   public long read (ByteBuffer[] dsts, int offset, int length)
+    throws IOException
   {
-    return 0;
+    // FIXME: Should we throw an exception if offset and/or length
+    // have wrong values ?
+
+    long result = 0;
+
+    for (int i = offset; i < offset + length; i++)
+      result += read (dsts [i]);
+
+    return result;
   }
     
   public SocketAddress receive (ByteBuffer dst)
+    throws IOException
   {
-    return null;
+    throw new Error ("Not implemented");
   }
     
   public int send (ByteBuffer src, SocketAddress target)
+    throws IOException
   {
-    return 0;
-  }
-    
-  public DatagramSocket socket ()
-  {
-    return null;
+    throw new Error ("Not implemented");
   }
 }
Index: gnu/java/nio/SocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SocketChannelImpl.java,v
retrieving revision 1.6
diff -u -b -B -r1.6 SocketChannelImpl.java
--- gnu/java/nio/SocketChannelImpl.java	18 Jun 2003 08:56:55 -0000	1.6
+++ gnu/java/nio/SocketChannelImpl.java	19 Jun 2003 16:36:35 -0000
@@ -118,22 +118,21 @@
 
   public int read (ByteBuffer dst) throws IOException
   {
+    byte[] data;
     int bytes = 0;
-    int len = 1024;
-    byte[]b = new byte[len];
+    int len = dst.remaining ();
 	
-    /*
-    bytes = SocketRead(fd, b, 0, len);
-    dst.put(b, 0, bytes);
-
-    if (bytes == 0)
+    if (!dst.hasArray ())
+      {
+        data = new byte [len];
+        dst.get (data, 0, len);
+      }
+    else
       {
-        // we've hit eof ?
-        return -1;
+        data = dst.array ();
       }
-    */
 
-    return bytes;
+    return socket.getInputStream().read (data, 0, len);
   }
     
   public long read (ByteBuffer[] dsts, int offset, int length)
@@ -152,24 +151,22 @@
   public int write (ByteBuffer src)
     throws IOException
   {
+    byte[] data;
     int bytes = 0;
-    int len = src.position();
+    int len = src.remaining ();
 
-    /*
-    if (src.hasArray ())
+    if (!src.hasArray ())
       {
-        byte[] b = src.array ();
-        bytes = SocketWrite (fd, b, 0, len);
+        data = new byte [len];
+        src.get (data, 0, len);
       }
     else
       {
-        byte[] b = new byte [len];
-        src.get (b, 0, len);
-        bytes = SocketWrite (fd, b, 0, len);
+        data = src.array ();
       }
-    */
 		
-    return bytes;
+    socket.getOutputStream().write (data, 0, len);
+    return len;
   }
 
   public long write (ByteBuffer[] srcs, int offset, int length)

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