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]

More java.net stuff for review


Hello list,

here is another java.net patch for review. Please comment.

Michael
-- 
Homepage: http://www.worldforge.org/
GPG-key: http://konqueror.dyndns.org/~mkoch/michael.gpg
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1444
diff -u -b -r1.1444 ChangeLog
--- ChangeLog	18 Sep 2002 10:15:50 -0000	1.1444
+++ ChangeLog	18 Sep 2002 11:18:17 -0000
@@ -1,3 +1,29 @@
+2002-09-19  Michael Koch  <konqueror@gmx.de>
+
+	* java/net/Socket.java
+	(sendUrgentData): New method.
+	(getChannel): New method.
+	* java/net/ServerSocket.java
+	(getChannel): New method.
+	(isBound): New method.
+	* java/net/DatagramSocket.java
+	(DatagramSocket): Two new methods.
+	(bind): New method.
+	(getChannel): New method.
+	(isBound): New method.
+	(send): Added newline to to make shorter lines.
+	* java/net/PlainDatagramSocketImpl.java
+	(mcastGrp): Added argument.
+	(join): Use new mcastGrp.
+	(leave): Use new mcastGrp.
+	(joinGroup): New method.
+	(leaveGroup): New method.
+	* java/net/natPlainDatagramSocketImpl.cc
+	(mcastGrp): Added argument, no yet really implemented.
+	(getOption): Added newline for shorter lines.
+	* java/net/natPlainSocketImpl.cc
+	(read, setOption, getOption): Added newline for shorter lines.
+
 2002-09-18  Michael Koch  <konqueror@gmx.de>
 
 	* java/util/regex/Matcher.java, java/util/regex/Pattern.java,
Index: java/net/Socket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/Socket.java,v
retrieving revision 1.12
diff -u -b -r1.12 Socket.java
--- java/net/Socket.java	11 Sep 2002 10:16:00 -0000	1.12
+++ java/net/Socket.java	18 Sep 2002 11:18:17 -0000
@@ -38,6 +38,7 @@
 package java.net;
 
 import java.io.*;
+import java.nio.channels.SocketChannel;
 
 /* Written using on-line Java Platform 1.2 API Specification.
  * Status:  I believe all methods are implemented.
@@ -78,6 +79,8 @@
    */
   SocketImpl impl;
 
+  SocketChannel ch; // this field must have been set if created by SocketChannel
+  
   // Constructors
 
   /**
@@ -525,6 +528,21 @@
   }
 
   /**
+   * Sends urgent data through the socket
+   *
+   * @param data The data to send.
+   * Only the lowest eight bits of data are sent
+   *
+   * @exception IOException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void sendUrgentData (int data) throws IOException
+  {
+    impl.sendUrgentData (data);
+  }
+
+  /**
    * Enables/disables the SO_OOBINLINE option
    * 
    * @param on True if SO_OOBLINE should be enabled 
@@ -818,5 +836,15 @@
   {
     if (impl != null)
       impl.shutdownOutput();
+  }
+
+  /**
+   * Returns the socket channel associated with this socket.
+   *
+   * It returns null if no associated socket exists.
+   */
+  public SocketChannel getChannel()
+  {
+    return ch;
   }
 }
Index: java/net/ServerSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/ServerSocket.java,v
retrieving revision 1.13
diff -u -b -r1.13 ServerSocket.java
--- java/net/ServerSocket.java	11 Sep 2002 10:16:00 -0000	1.13
+++ java/net/ServerSocket.java	18 Sep 2002 11:18:17 -0000
@@ -38,6 +38,7 @@
 package java.net;
 
 import java.io.IOException;
+import java.nio.channels.ServerSocketChannel;
 
 /* Written using on-line Java Platform 1.2 API Specification.
  * Status:  I believe all methods are implemented.
@@ -75,6 +76,12 @@
   private SocketImpl impl;
 
   /**
+   * ServerSocketChannel of this ServerSocket. This channel only exists
+   * when the socket is created by ServerSocketChannel.open().
+   */
+  private ServerSocketChannel ch;
+
+  /**
    * Private constructor that simply sets the implementation.
    */
   private ServerSocket()
@@ -279,6 +286,39 @@
   public void close () throws IOException
   {
     impl.close();
+  }
+
+  /**
+   * Returns the unique ServerSocketChannel object
+   * associated with this socket, if any.
+   *
+   * The socket only has a ServerSocketChannel if its created
+   * by ServerSocketChannel.open.
+   * 
+   * @since 1.4
+   */
+  public ServerSocketChannel getChannel()
+  {
+    return ch;
+  }
+
+  /**
+   * Returns true then the socket is bound, otherwise false
+   * 
+   * @since 1.4
+   */
+  public boolean isBound()
+  {
+    try
+      {
+        Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
+      }
+    catch (SocketException e)
+      {
+	return false;
+      }
+    
+    return true;
   }
 
   /**
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.12
diff -u -b -r1.12 DatagramSocket.java
--- java/net/DatagramSocket.java	4 Sep 2002 17:35:22 -0000	1.12
+++ java/net/DatagramSocket.java	18 Sep 2002 11:18:17 -0000
@@ -1,6 +1,6 @@
 // DatagramSocket.java
 
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -10,6 +10,7 @@
 
 package java.net;
 import java.io.IOException;
+import java.nio.channels.DatagramChannel;
 
 /**
  * @author Warren Levy <warrenl@cygnus.com>
@@ -26,12 +27,42 @@
 {
   DatagramSocketImpl impl;
 
+  DatagramChannel ch;
+
   public DatagramSocket() throws SocketException
   {
     this(0, null);
   }
 
   /**
+   * Creates a DatagramSocket from a specified DatagramSocketImpl instance
+   *
+   * @param impl The DatagramSocketImpl the socket will be created from
+   * 
+   * @since 1.4
+   */
+  protected DatagramSocket (DatagramSocketImpl impl)
+  {
+    this.impl = impl;
+  }
+
+  /**
+   * Creates a datagram socket that is bound to a given socket address
+   *
+   * @param bindaddr The socket address to bind to
+   *
+   * @exception SocketException If an error occurs
+   * 
+   * @since 1.4
+   */
+  public DatagramSocket (SocketAddress bindaddr)
+    throws SocketException
+  {
+    this (((InetSocketAddress) bindaddr).getPort (),
+          ((InetSocketAddress) bindaddr).getAddress ());
+  }
+
+  /**
    * Creates a datagram socket that is bound to a specific port
    *
    * @param port The port number to bind to
@@ -85,6 +116,22 @@
   }
 
   /**
+   * Binds the socket to the given socket addres
+   *
+   * @param address The socket address to bind to
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void bind (SocketAddress address)
+    throws SocketException
+  {
+    InetSocketAddress tmp = (InetSocketAddress) address;
+    impl.bind (tmp.getPort (), tmp.getAddress ());
+  }
+  
+  /**
    * Closes the datagram socket
    */
   public void close()
@@ -93,6 +140,16 @@
   }
 
   /**
+   * Gets a datagram channel assoziated with the socket
+   * 
+   * @since 1.4
+   */
+  public DatagramChannel getChannel()
+  {
+    return ch;
+  }
+
+  /**
    * Returns the local address of the datagram socket
    * 
    * @since 1.1
@@ -199,7 +256,8 @@
 	  s.checkConnect(addr.getHostAddress(), p.getPort());
       }
 
-    // FIXME: if this is a subclass of MulticastSocket, use getTimeToLive for TTL val.
+    // FIXME: if this is a subclass of MulticastSocket,
+    // use getTimeToLive for TTL val.
     impl.send(p);
   }
 
@@ -244,6 +302,25 @@
   public void disconnect()
   {
     //impl.disconnect();
+  }
+
+  /**
+   * Returns the binding state of the socket
+   * 
+   * @since 1.4
+   */
+  public boolean isBound()
+  {
+    try
+      {
+        Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
+      }
+    catch (SocketException e)
+      {
+        return false;
+      }
+
+    return true;
   }
 
   /**
Index: java/net/PlainDatagramSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainDatagramSocketImpl.java,v
retrieving revision 1.13
diff -u -b -r1.13 PlainDatagramSocketImpl.java
--- java/net/PlainDatagramSocketImpl.java	12 Sep 2002 06:35:51 -0000	1.13
+++ java/net/PlainDatagramSocketImpl.java	18 Sep 2002 11:18:17 -0000
@@ -72,8 +72,8 @@
   protected native void receive(DatagramPacket p) throws IOException;
   public native void setOption(int optID, Object value) throws SocketException;
   public native Object getOption(int optID) throws SocketException;
-  private native void mcastGrp(InetAddress inetaddr, boolean join)
-	  throws IOException;
+  private native void mcastGrp(InetAddress inetaddr, NetworkInterface netIf,
+		               boolean join) throws IOException;
   protected native void close();
 
   // Deprecated in JDK 1.2.
@@ -90,12 +90,24 @@
 
   protected void join(InetAddress inetaddr) throws IOException
   {
-    mcastGrp(inetaddr, true);
+    mcastGrp(inetaddr, null, true);
   }
 
   protected void leave(InetAddress inetaddr) throws IOException
   {
-    mcastGrp(inetaddr, false);
+    mcastGrp(inetaddr, null, false);
+  }
+
+  protected void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+	  throws IOException
+  {
+    mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, true);
+  }
+
+  protected void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+	  throws IOException
+  {
+    mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, false);
   }
 
   protected void finalize() throws Throwable
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.45
diff -u -b -r1.45 natPlainDatagramSocketImpl.cc
--- java/net/natPlainDatagramSocketImpl.cc	14 Sep 2002 21:56:44 -0000	1.45
+++ java/net/natPlainDatagramSocketImpl.cc	18 Sep 2002 11:18:17 -0000
@@ -63,6 +63,7 @@
 #include <java/net/SocketException.h>
 #include <java/net/PlainDatagramSocketImpl.h>
 #include <java/net/InetAddress.h>
+#include <java/net/NetworkInterface.h>
 #include <java/net/DatagramPacket.h>
 #include <java/lang/InternalError.h>
 #include <java/lang/Object.h>
@@ -136,6 +137,7 @@
 
 void
 java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *,
+                                              java::net::NetworkInterface *,
 					      jboolean)
 {
   throw new java::io::IOException (
@@ -504,8 +506,11 @@
 
 void
 java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
+                                              java::net::NetworkInterface *,
 					      jboolean join)
 {
+  // FIXME: implement use of NetworkInterface
+
   union McastReq u;
   jbyteArray haddress = inetaddr->addr;
   jbyte *bytes = elements (haddress);
@@ -769,7 +774,8 @@
 	      }
 #endif
 	    else
-	      throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
+	      throw new java::net::SocketException (
+			      JvNewStringUTF ("invalid family"));
 	    localAddress = new java::net::InetAddress (laddr, NULL);
 	  }
 	return localAddress;  
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.48
diff -u -b -r1.48 natPlainSocketImpl.cc
--- java/net/natPlainSocketImpl.cc	16 Sep 2002 16:42:40 -0000	1.48
+++ java/net/natPlainSocketImpl.cc	18 Sep 2002 11:18:17 -0000
@@ -588,7 +588,8 @@
     timeout_value.tv_sec = timeout / 1000;
     timeout_value.tv_usec = (timeout % 1000) * 1000;
     // Select on the fds.
-    int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+    int sel_retval =
+	    _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
     // If select returns 0 we've waited without getting data...
     // that means we've timed out.
     if (sel_retval == 0)
@@ -647,7 +648,8 @@
     timeout_value.tv_sec = timeout / 1000;
     timeout_value.tv_usec =(timeout % 1000) * 1000;
     // Select on the fds.
-    int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+    int sel_retval = 
+	    _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
     // We're only interested in the 0 return.
     // error returns still require us to try to read 
     // the socket to see what happened.
@@ -776,7 +778,8 @@
     }
   else
     {
-      throw new java::lang::IllegalArgumentException (JvNewStringLatin1 ("`value' must be Boolean or Integer"));
+      throw new java::lang::IllegalArgumentException (
+        JvNewStringLatin1 ("`value' must be Boolean or Integer"));
     }
 
   switch (optID) 
@@ -968,8 +971,8 @@
 	      }
 #endif
 	    else
-	      throw
-		new java::net::SocketException (JvNewStringUTF ("invalid family"));
+	      throw new java::net::SocketException (
+			      JvNewStringUTF ("invalid family"));
 	    localAddress = new java::net::InetAddress (laddr, NULL);
 	  }
 	return localAddress;

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