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]

java.net patch


Hi list,


I have writte a bigger patch for java/net. Most of its stuff doesnt suit into 
classpath. I will later see what can be merged betweeen both.

Please review this patch.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1429
diff -u -b -r1.1429 ChangeLog
--- ChangeLog	4 Sep 2002 05:34:11 -0000	1.1429
+++ ChangeLog	4 Sep 2002 16:34:45 -0000
@@ -1,3 +1,46 @@
+2002-09-05  Michael Koch  <konqueror@gmx.de>
+
+	* java/net/DatagramSocket.java
+	(DatagramSocket): Added documentation.
+	(close): Likewise.
+	(getLocalAddress): Likewise.
+	(getLocalPort): Likewise.
+	(receive): Likewise.
+	(send): Likewise.
+	(setSoTimeout): Likewise.
+	(connect): New method.
+	(disconnect): New method.
+	(getInetAddress): New method (FIXME)
+	(getPort): New method.
+	(setReuseAddress): New method.
+	(getReuseAddress): New method.
+	(setBroadcast): New method.
+	(getBroadcast): New method.
+	(setTrafficClass): New method.
+	(getTrafficClass): New method.
+	* java/net/MulticastSocket.java):
+	(getTTL): Added @see in documentation.
+	(setTTL): Added @see in documentation.
+	(setLoopbackMode): New method.
+	(getLoopbackMode): New method.
+	* java/net/PlainSocketImpl.java:
+	Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+	* java/net/PlainDatagramSocketImpl.java
+	Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+	* java/net/natPlainSocketImpl.cc
+	(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+	(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+	This should also fix SO_KEEPALIVE
+	* java/net/natPlainDatagramSocketImpl.cc
+	(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+	(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
+	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
+
 2002-09-04  Michael Koch  <konqueror@gmx.de>
 
 	* java/net/SocketOptions.java: added static variables to be JDK 1.4
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.11
diff -u -b -r1.11 DatagramSocket.java
--- java/net/DatagramSocket.java	27 Aug 2002 17:47:26 -0000	1.11
+++ java/net/DatagramSocket.java	4 Sep 2002 16:34:45 -0000
@@ -31,11 +31,26 @@
     this(0, null);
   }
 
+  /**
+   * Creates a datagram socket that is bound to a specific port
+   *
+   * @param port The port number to bind to
+   *
+   * @exception SocketException If an error occurs
+   */
   public DatagramSocket(int port) throws SocketException
   {
     this(port, null);
   }
 
+  /**
+   * Creates a datagram socket that is bound to a specific port/inet address
+   *
+   * @param port The port number to bind to
+   * @param laddr The local address to bind to
+   *
+   * @exception SocketException If an error occurs
+   */
   public DatagramSocket(int port, InetAddress laddr) throws SocketException
   {
     if (port < 0 || port > 65535)
@@ -69,11 +84,19 @@
     impl.bind(port, laddr == null ? InetAddress.ANY_IF : laddr);
   }
 
+  /**
+   * Closes the datagram socket
+   */
   public void close()
   {
     impl.close();
   }
 
+  /**
+   * Returns the local address of the datagram socket
+   * 
+   * @since 1.1
+   */
   public InetAddress getLocalAddress()
   {
     SecurityManager s = System.getSecurityManager();
@@ -112,12 +135,23 @@
       }
   }
 
+  /**
+   * Returns the local port this socket uses
+   *
+   * @return The local port number
+   */
   public int getLocalPort()
   {
     return impl.getLocalPort();
   }
 
   /**
+   * Gets the SO_TIMEOUT value
+   *
+   * @return The current timeout in milliseconds
+   *
+   * @exception SocketException If an error occurs
+   * 
    * @since 1.1
    */
   public synchronized int getSoTimeout() throws SocketException
@@ -129,6 +163,13 @@
       return 0;
   }
 
+  /**
+   * Receive a datagram packet
+   *
+   * @param p The datagram packet to put the incoming data into
+   * 
+   * @exception IOException If an error occurs
+   */
   public synchronized void receive(DatagramPacket p) throws IOException
   {
     SecurityManager s = System.getSecurityManager();
@@ -138,6 +179,13 @@
     impl.receive(p);
   }
 
+  /**
+   * Sends a datagram packet
+   *
+   * @param p The datagram packet to send
+   *
+   * @exception IOException If an error occurs
+   */
   public void send(DatagramPacket p) throws IOException
   {
     // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
@@ -151,11 +199,17 @@
 	  s.checkConnect(addr.getHostAddress(), p.getPort());
       }
 
-    // FIXME: if this is a subclass of MulticastSocket, use getTTL for TTL val.
+    // FIXME: if this is a subclass of MulticastSocket, use getTimeToLive for TTL val.
     impl.send(p);
   }
 
   /**
+   * Sets a new value for SO_TIMEOUT
+   *
+   * @param timeout The timeout in milliseconds
+   *
+   * @exception SocketException If an error occurs
+   *
    * @since 1.1
    */
   public synchronized void setSoTimeout(int timeout) throws SocketException
@@ -166,25 +220,53 @@
     impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
   }
 
-  // JDK1.2
-  // public void connect(InetAddress address, int port)
-  // {
-  // }
-
-  // JDK1.2
-  // public void disconnect()
-  // {
-  // }
-
-  // JDK1.2
-  // public InetAddress getInetAddress()
-  // {
-  // }
-
-  // JDK1.2
-  // public int getPort()
-  // {
-  // }
+  /**
+   * Connects the datagrem socket to a specified address/port
+   *
+   * @param address The address to connect to
+   * @param port The port to connect to
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.2
+   */
+  public void connect(InetAddress address, int port)
+    throws SocketException
+  {
+    //impl.connect(address, port);
+  }
+
+  /**
+   * Disconnects the datagram socket
+   *
+   * @since 1.2
+   */
+  public void disconnect()
+  {
+    //impl.disconnect();
+  }
+
+  /**
+   * Returns the InetAddress the socket is connected to
+   * or null if the socket is not connected
+   * 
+   * @since 1.2
+   */
+  public InetAddress getInetAddress()
+  {
+    // FIXME:
+    return null;
+  }
+
+  /**
+   * Returns the local port number of the socket
+   * 
+   * @since 1.2
+   */
+  public int getPort()
+  {
+    return impl.localPort;
+  }
 
   /**
    * This method returns the value of the system level socket option
@@ -207,6 +289,107 @@
       throw new SocketException("Unexpected type");
   }
 
+  /**
+   * Enables/Disables SO_REUSEADDR
+   * 
+   * @param on Whether or not to have SO_REUSEADDR turned on
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void setReuseAddress(boolean on) throws SocketException
+  {
+    impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
+  }
+
+  /**
+   * Checks if SO_REUSEADDR is enabled
+   *
+   * @exception SocketException If an error occurs
+   * 
+   * @since 1.4
+   */
+  public boolean getReuseAddress() throws SocketException
+  {
+    Object obj = impl.getOption (SocketOptions.SO_REUSEADDR);
+  
+    if (obj instanceof Boolean)
+      return(((Boolean) obj).booleanValue ());
+    else 
+      throw new SocketException ("Unexpected type");
+  }
+
+  /**
+   * Enables/Disables SO_BROADCAST
+   * 
+   * @param on Whether or not to have SO_BROADCAST turned on
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void setBroadcast(boolean on) throws SocketException
+  {
+    impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on));
+  }
+
+  /**
+   * Checks if SO_BROADCAST is enabled
+   * 
+   * @exception SocketException If an error occurs
+   * 
+   * @since 1.4
+   */
+  public boolean getBroadcast() throws SocketException
+  {
+    Object obj = impl.getOption (SocketOptions.SO_BROADCAST);
+  
+    if (obj instanceof Boolean)
+      return ((Boolean) obj).booleanValue ();
+    else 
+      throw new SocketException ("Unexpected type");
+  }
+
+  /**
+   * Sets the traffic class value
+   *
+   * @param tc The traffic class
+   *
+   * @exception SocketException If an error occurs
+   * @exception IllegalArgumentException If tc < 0 or rc > 255
+   *
+   * @see DatagramSocket:getTrafficClass
+   * 
+   * @since 1.4
+   */
+  public void setTrafficClass(int tc)
+    throws SocketException
+  {
+    if (tc < 0 || tc > 255) throw new IllegalArgumentException();
+
+    impl.setOption (SocketOptions.IP_TOS, new Integer (tc));
+  }
+  
+  /**
+   * Returns the current traffic class
+   * 
+   * @see DatagramSocket:setTrafficClass
+   *
+   * @exception SocketException If an error occurs
+   * 
+   * @since 1.4
+   */
+  public int getTrafficClass() throws SocketException
+  {
+    Object obj = impl.getOption(SocketOptions.IP_TOS);
+
+    if (obj instanceof Integer)
+      return ((Integer) obj).intValue ();
+    else
+      throw new SocketException ("Unexpected type");
+  }
+  
   /**
    * This method returns the value of the system level socket option
    * SO_SNDBUF, which is used by the operating system to tune buffer
Index: java/net/MulticastSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/MulticastSocket.java,v
retrieving revision 1.12
diff -u -b -r1.12 MulticastSocket.java
--- java/net/MulticastSocket.java	2 Sep 2002 09:19:08 -0000	1.12
+++ java/net/MulticastSocket.java	4 Sep 2002 16:34:45 -0000
@@ -114,6 +114,8 @@
    * @exception IOException If an error occurs
    *
    * @deprecated 1.2 Replaced by getTimeToLive()
+   *
+   * @see Multicastsocket:getTimeToLive
    */
   public byte getTTL() throws IOException
   {
@@ -151,6 +153,42 @@
   }
 
   /**
+   * Disable/Enable local loopback of multicast packets.  The option is used by
+   * the platform's networking code as a hint for setting whether multicast
+   * data will be looped back to the local socket. 
+   *
+   * Because this option is a hint, applications that want to verify what
+   * loopback mode is set to should call #getLoopbackMode
+   *
+   * @param disable True to disable loopback mode
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void setLoopbackMode(boolean disable) throws SocketException
+  {
+    impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable));
+  }
+
+  /**
+   * Checks if local loopback mode is enabled or not
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public boolean getLoopbackMode() throws SocketException
+  {
+    Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP);
+
+    if (obj instanceof Boolean)
+      return ((Boolean) obj).booleanValue ();
+    else
+      throw new SocketException ("Unexpected type");
+  }
+
+  /**
    * Sets the "Time to Live" value for a socket.  The value must be between
    * 1 and 255.
    *
@@ -159,6 +197,8 @@
    * @exception IOException If an error occurs
    *
    * @deprecated 1.2 Replaced by <code>setTimeToLive</code>
+   *
+   * @see MulticastSocket:setTimeToLive
    */
   public void setTTL(byte ttl) throws IOException
   {
Index: java/net/PlainSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainSocketImpl.java,v
retrieving revision 1.11
diff -u -b -r1.11 PlainSocketImpl.java
--- java/net/PlainSocketImpl.java	30 Aug 2002 18:16:00 -0000	1.11
+++ java/net/PlainSocketImpl.java	4 Sep 2002 16:34:46 -0000
@@ -28,7 +28,12 @@
   static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
                    _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
                    _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
+                   _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
+                   _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
 		   _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
+                   _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
+                   _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
+                   _Jv_IP_TOS_ = SocketOptions.IP_TOS,
                    _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
                    _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
                    _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
Index: java/net/PlainDatagramSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainDatagramSocketImpl.java,v
retrieving revision 1.11
diff -u -b -r1.11 PlainDatagramSocketImpl.java
--- java/net/PlainDatagramSocketImpl.java	30 Aug 2002 18:16:00 -0000	1.11
+++ java/net/PlainDatagramSocketImpl.java	4 Sep 2002 16:34:46 -0000
@@ -29,7 +29,12 @@
   static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
                    _Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
                    _Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
+                   _Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
+                   _Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
 		   _Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
+                   _Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
+                   _Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
+                   _Jv_IP_TOS_ = SocketOptions.IP_TOS,
                    _Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
                    _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
                    _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.44
diff -u -b -r1.44 natPlainSocketImpl.cc
--- java/net/natPlainSocketImpl.cc	30 Aug 2002 18:16:00 -0000	1.44
+++ java/net/natPlainSocketImpl.cc	4 Sep 2002 16:34:46 -0000
@@ -747,6 +747,18 @@
         if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
 	    val_len) != 0)
 	  goto error;
+	break;
+      
+      case _Jv_SO_BROADCAST_ :
+        throw new java::lang::InternalError (
+          JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
+	break;
+	
+      case _Jv_SO_OOBINLINE_ :
+        if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+	    val_len) != 0)
+	  goto error;
+	break;
 
       case _Jv_SO_LINGER_ :
 #ifdef SO_LINGER
@@ -781,6 +793,23 @@
         throw new java::net::SocketException (
           JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
         return;
+	
+      case _Jv_IP_MULTICAST_IF2_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+        break;
+	
+      case _Jv_IP_MULTICAST_LOOP_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+	break;
+	
+      case _Jv_IP_TOS_ :
+        if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+	   val_len) != 0)
+	  goto error;    
+	break;
+	
       case _Jv_SO_REUSEADDR_ :
         throw new java::net::SocketException (
           JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
@@ -844,6 +873,18 @@
         else
 	  return new java::lang::Boolean (val != 0);
 
+      case _Jv_SO_BROADCAST_ :
+        if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+	   &val_len) != 0)
+	  goto error;    
+        return new java::lang::Boolean ((__java_boolean)val);
+	
+      case _Jv_SO_OOBINLINE_ :
+        if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
+	    &val_len) != 0)
+	  goto error;    
+        return new java::lang::Boolean ((__java_boolean)val);
+	
       case _Jv_SO_RCVBUF_ :
       case _Jv_SO_SNDBUF_ :
 #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@@ -888,6 +929,24 @@
 	throw new java::net::SocketException (
 	  JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
 	break;
+	
+      case _Jv_IP_MULTICAST_IF2_ :
+	throw new java::net::SocketException (
+	  JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+	break;
+	
+      case _Jv_IP_MULTICAST_LOOP_ :
+	throw new java::net::SocketException(
+          JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+	break;
+	
+      case _Jv_IP_TOS_ :
+        if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+           &val_len) != 0)
+          goto error;
+        return new java::lang::Integer (val);
+	break;
+	
       case _Jv_SO_REUSEADDR_ :
 	throw new java::net::SocketException (
 	  JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.41
diff -u -b -r1.41 natPlainDatagramSocketImpl.cc
--- java/net/natPlainDatagramSocketImpl.cc	30 Aug 2002 18:16:00 -0000	1.41
+++ java/net/natPlainDatagramSocketImpl.cc	4 Sep 2002 16:34:46 -0000
@@ -528,6 +528,18 @@
         throw new java::net::SocketException (
           JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
         return;
+	
+      case _Jv_SO_BROADCAST_ :
+        if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+                          val_len) != 0)
+          goto error;
+        break;
+	
+      case _Jv_SO_OOBINLINE_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
+        break;
+	
       case _Jv_SO_SNDBUF_ :
       case _Jv_SO_RCVBUF_ :
 #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@@ -591,6 +603,23 @@
 	if (::setsockopt (fnum, level, opname, ptr, len) != 0)
 	  goto error;
         return;
+	
+      case _Jv_IP_MULTICAST_IF2_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+        break;
+	
+      case _Jv_IP_MULTICAST_LOOP_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
+        break;
+	
+      case _Jv_IP_TOS_ :
+        if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+	   val_len) != 0)
+	  goto error;    
+	return;
+
       case _Jv_SO_TIMEOUT_ :
 	timeout = val;
         return;
@@ -625,6 +654,18 @@
         throw new java::net::SocketException (
           JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
         break;
+
+      case _Jv_SO_BROADCAST_ :
+	if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
+	    &val_len) != 0)
+	  goto error;
+	return new java::lang::Boolean (val != 0);
+	
+      case _Jv_SO_OOBINLINE_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
+	break;
+	
       case _Jv_SO_RCVBUF_ :
       case _Jv_SO_SNDBUF_ :
 #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@@ -697,6 +738,24 @@
       case _Jv_SO_TIMEOUT_ :
 	return new java::lang::Integer (timeout);
 	break;
+	
+      case _Jv_IP_MULTICAST_IF2_ :
+        throw new java::net::SocketException (
+          JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
+        break;
+	
+      case _Jv_IP_MULTICAST_LOOP_ :
+	if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
+	    &val_len) != 0)
+	  goto error;
+	return new java::lang::Boolean (val != 0);
+	
+      case _Jv_IP_TOS_ :
+        if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
+           &val_len) != 0)
+          goto error;
+        return new java::lang::Integer (val);
+
       default :
 	errno = ENOPROTOOPT;
     }

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