classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Intel's patch submission...


From: Mark Wielaard
Subject: Re: Intel's patch submission...
Date: 20 Oct 2002 13:13:47 +0200

Hi,

On Sat, 2002-10-19 at 08:26, Michael Koch wrote:
> > - Refocator InetAddress.
> 
> This interferes with my work, as I'm going to merge this class with 
> libgcj. And there are some Inet4Address/Inet6Address issues. 
> Esspecially IPv6 support never really worked. Can you send me the 
> file ? I will try to merge with my things and then best ideas for 
> implementation will win ;-)

I have attached the InetAddress part of the patch.

2002-07-25  Wu Gansha <address@hidden>

    * classpath/java/net/InetAddress.java: removed the use of my_ip
    array, refactored many codes.

Cheers,

Mark
--- /home/cbj/cvs/classpath/./java/net/InetAddress.java Sun Mar 24 23:59:08 2002
+++ ./java/net/InetAddress.java Tue Jul 16 10:26:56 2002
@@ -39,7 +39,7 @@
 package java.net;
 
 import java.io.Serializable;
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.StringTokenizer;
 
 import gnu.classpath.Configuration;
@@ -79,9 +79,11 @@
 private static final long serialVersionUID = 3286316764910316507L;
 
 /**
-  * The default DNS hash table size
+  * The default DNS hash table size, 
+  * use a prime number happy with hash table
   */
-private static final int DEFAULT_CACHE_SIZE = 400;
+  
+private static final int DEFAULT_CACHE_SIZE = 89; 
 
 /**
   * The default caching period in minutes
@@ -118,9 +120,11 @@
 private static int cache_purge_pct = 0;
 
 /**
-  * Hashtable to use as DNS lookup cache
+  * Hashtable to use as DNS lookup cache, 
+  * use HashMap because all accesses to cache are already synchronized
   */
-private static Hashtable cache;
+private static HashMap cache;
+
 
 // Static initializer for the cache
 static
@@ -140,7 +144,7 @@
 
   // Create the cache
   if (cache_size != 0)
-      cache = new Hashtable(cache_size);
+      cache = new HashMap(cache_size);
 
   // precompute the ANY_IF address
   try
@@ -162,11 +166,6 @@
  */
 
 /**
-  * An array of octets representing an IP address
-  */
-transient int[] my_ip;
-
-/**
   * The name of the host for this address
   */
 String hostName;
@@ -382,7 +381,7 @@
        }
    }
 
-  // Wasn't and IP, so try the lookup
+  // Wasn't an IP, so try the lookup
   InetAddress[] addrs = getAllByName(hostname);
   
   return(addrs[0]);
@@ -413,7 +412,7 @@
  */
 
 /**
-  * Initializes this object's my_ip instance variable from the passed in
+  * Initializes this object's address info from the passed in
   * int array.  Note that this constructor is protected and is called
   * only by static methods in this class.
   *
@@ -425,10 +424,23 @@
   this(addr, null, null);
 }
 
+/**
+  * Initializes this object's address info from the passed in
+  * int address.  Note that this constructor is private and is called
+  * only by this class and native methods.
+  *
+  * @param address The address as an int
+  */
+private
+InetAddress(int address){
+    family = 2; /*AF_INET*/
+    this.address = address;
+}
+
 /*************************************************************************/
 
 /**
-  * Initializes this object's my_ip instance variable from the passed in
+  * Initializes this object's address info from the passed in
   * int array.  Note that this constructor is protected and is called
   * only by static methods in this class.
   *
@@ -444,7 +456,7 @@
 /*************************************************************************/
 
 /**
-  * Initializes this object's my_ip instance variable from the passed in
+  * Initializes this object's address info from the passed in
   * int array.  Note that this constructor is protected and is called
   * only by static methods in this class.
   *
@@ -455,16 +467,12 @@
 private
 InetAddress(int[] addr, String hostname, String hostname_alias)
 {
-  my_ip = new int[addr.length];
-
-  for (int i = 0; i < addr.length; i++)
-    my_ip[i] = addr[i];    
-
   this.hostName = hostname;
   this.hostname_alias = hostname_alias;
   lookup_time = System.currentTimeMillis();
 
   family = 2; /* AF_INET */
+  // compose the int address
   address = addr[3] & 0xff;
   address |= ((addr[2] << 8) & 0xff00);
   address |= ((addr[1] << 16) & 0xff0000);
@@ -493,14 +501,8 @@
   if (!(addr instanceof InetAddress))
     return(false);
 
-  byte[] test_ip = ((InetAddress)addr).getAddress();
-
-  if (test_ip.length != my_ip.length)
-    return(false);
-
-  for (int i = 0; i < my_ip.length; i++)
-    if (test_ip[i] != (byte)my_ip[i])
-       return(false);
+  if (address != ((InetAddress)addr).address)
+    return false;
 
   return(true);
 }
@@ -515,12 +517,13 @@
 public byte[]
 getAddress()
 {
-  byte[] addr = new byte[my_ip.length];
+  // compose addr array on the fly
+  byte[] addr = new byte[4];
 
-  for (int i = 0; i < my_ip.length; i++)
-    {
-      addr[i] = (byte)my_ip[i];
-    }
+  addr[3] = (byte)(address & 0xff);
+  addr[2] = (byte)((address >>> 8) & 0xff);
+  addr[1] = (byte)((address >>> 16) & 0xff);
+  addr[0] = (byte)((address >>> 24) & 0xff);
 
   return(addr);
 }
@@ -538,12 +541,13 @@
 {
   StringBuffer addr = new StringBuffer();
 
-  for (int i = 0; i < my_ip.length; i++)
-    {
-      addr.append((int)my_ip[i]);
-      if (i < (my_ip.length - 1))
-        addr.append(".");
-    }
+  addr.append((address >>> 24) & 0xff);
+  addr.append('.');
+  addr.append((address >>> 16) & 0xff);
+  addr.append('.');
+  addr.append((address >>> 8) & 0xff);
+  addr.append('.');
+  addr.append(address & 0xff);
 
   return(addr.toString());
 }
@@ -564,7 +568,12 @@
 
   try
     {
-      hostName = getHostByAddr(my_ip);  
+      int[] addr = new int[4];
+      addr[3] = address & 0xff;
+      addr[2] = (address >>> 8) & 0xff;
+      addr[1] = (address >>> 16) & 0xff;
+      addr[0] = (address >>> 24) & 0xff;
+      hostName = getHostByAddr(addr);  
       return(hostName);
     }
   catch (UnknownHostException e)
@@ -589,13 +598,9 @@
 {
   long val1 = 0, val2 = 0;
 
-  // Its obvious here that I have no idea how to generate a good
-  // hash key
-  for (int i = 0; i < my_ip.length; i++)
-    val1 = val1 + (my_ip[i] << ((my_ip.length - i) / 8));
-
-  for (int i = 0; i < my_ip.length; i++)
-    val2 = val2 + (my_ip[i] * 10 * i);
+  // a simpler hash algorithm
+  val1 = address & 0xffff;
+  val2 = address >> 16;
 
   val1 = (val1 >> 1) ^ val2;
 
@@ -614,14 +619,8 @@
 public boolean
 isMulticastAddress()
 {
-  if (my_ip.length == 0)
-    return(false);
-
-  // Mask against high order bits of 1110
-  if ((my_ip[0] & 0xF0) == 224)
-    return(true);
-
-  return(false);
+  // 224 = 0xe0
+  return (address & 0xf0000000) == 0xe0000000;
 }
 
 /*************************************************************************/
@@ -636,7 +635,8 @@
 public String
 toString()
 {
-  return(getHostAddress());
+  //jBoss seems like this 
+  return (getHostName() + "/" + getHostAddress()); 
 }
 
 /*************************************************************************/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]