Hi all,

attached is another patch from Guilhem that fixes DatagramSocket constructor behaviour & comments. It resulted as a fix to a bug report to the kaffe mailing list from Everton da Silva Marques [1]. Please also take a look at the discussion in the thread about other approaches to fix the issue, and why they weren't picked.


2003-11-21 Guilhem Lavaux <[EMAIL PROTECTED]>


        * libraries/javalib/java/net/DatagramSocket.java
        ((DatagramSocket(SocketAddress)): Fixed comment to match
        method. If address is null leave socket unbound.
        (DatagramSocket(int, InetAddress)): Rewritten to delegate
        to ((DatagramSocket(SocketAddress)) in order to pick up
        the fix. Moved checking code into
        ((DatagramSocket(SocketAddress)).


cheers, dalibor topic

[1] http://www.mail-archive.com/[EMAIL PROTECTED]/msg03573.html
--- /var/tmp/PROJECTS/classpath//./java/net/DatagramSocket.java Mon Sep 22 16:56:08 
2003
+++ /tmp/topic/kaffe/libraries/javalib/java/net/DatagramSocket.java     Mon Nov  3 
18:24:43 2003
@@ -146,13 +146,24 @@
    */
   public DatagramSocket(int port, InetAddress laddr) throws SocketException
   {
-    if (port < 0 || port > 65535)
-      throw new IllegalArgumentException("Invalid port: " + port);
-
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkListen(port);
+    this(new InetSocketAddress (laddr, port));
+  }
 
+  /**
+   * Initializes a new instance of <code>DatagramSocket</code> that binds to 
+   * the specified local port and address.
+   *
+   * @param address address to bind the socket to. If address is null,
+   * the socket is left unbound.
+   *
+   * @exception SecurityException If a security manager exists and its
+   * <code>checkListen</code> method doesn't allow the operation.
+   * @exception SocketException If an error occurs.
+   *
+   * @since 1.4
+   */
+  public DatagramSocket (SocketAddress address) throws SocketException
+  {
     String propVal = System.getProperty("impl.prefix");
     if (propVal == null || propVal.equals(""))
       impl = new PlainDatagramSocketImpl();
@@ -170,12 +181,26 @@
        }
     impl.create();
 
+    // If address is null just return immediately.
+    if (address == null)
+      return;
+
+    InetSocketAddress is_addr = (InetSocketAddress)address;
+    InetAddress laddr;
+
+    laddr = is_addr.getAddress();
     if (laddr == null)
       laddr = InetAddress.ANY_IF;
-    
+    if (is_addr.getPort() < 0 || is_addr.getPort() > 65535)
+      throw new IllegalArgumentException("Invalid port: " + is_addr.getPort());
+
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkListen (is_addr.getPort());
+ 
     try
       {
-        impl.bind (port, laddr);
+        impl.bind (is_addr.getPort(), laddr);
       }
     catch (SocketException exception)
       {
@@ -193,25 +218,6 @@
         throw error;
       }
   }
-
-  /**
-   * Initializes a new instance of <code>DatagramSocket</code> that binds to 
-   * the specified local port and address.
-   *
-   * @param port The local port number to bind to.
-   * @param laddr The local address to bind to.
-   *
-   * @exception SecurityException If a security manager exists and its
-   * <code>checkListen</code> method doesn't allow the operation.
-   * @exception SocketException If an error occurs.
-   *
-   * @since 1.4
-   */
-  public DatagramSocket (SocketAddress address) throws SocketException
-  {
-    this (((InetSocketAddress) address).getPort (),
-          ((InetSocketAddress) address).getAddress ());
-  }
   
   /**
    * Closes this datagram socket.
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to