diff options
Diffstat (limited to 'libjava/classpath/java/net')
-rw-r--r-- | libjava/classpath/java/net/DatagramSocket.java | 7 | ||||
-rw-r--r-- | libjava/classpath/java/net/InetAddress.java | 139 | ||||
-rw-r--r-- | libjava/classpath/java/net/URL.java | 9 |
3 files changed, 16 insertions, 139 deletions
diff --git a/libjava/classpath/java/net/DatagramSocket.java b/libjava/classpath/java/net/DatagramSocket.java index 40bafbb34dd..d8837c006b5 100644 --- a/libjava/classpath/java/net/DatagramSocket.java +++ b/libjava/classpath/java/net/DatagramSocket.java @@ -176,7 +176,12 @@ public class DatagramSocket { String propVal = SystemProperties.getProperty("impl.prefix"); if (propVal == null || propVal.equals("")) - impl = new PlainDatagramSocketImpl(); + { + if (factory != null) + impl = factory.createDatagramSocketImpl(); + else + impl = new PlainDatagramSocketImpl(); + } else try { diff --git a/libjava/classpath/java/net/InetAddress.java b/libjava/classpath/java/net/InetAddress.java index 94dc6cb6d84..7277331bb26 100644 --- a/libjava/classpath/java/net/InetAddress.java +++ b/libjava/classpath/java/net/InetAddress.java @@ -43,7 +43,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamException; import java.io.Serializable; -import java.util.HashMap; import java.util.StringTokenizer; /** @@ -66,22 +65,6 @@ public class InetAddress implements Serializable private static final long serialVersionUID = 3286316764910316507L; /** - * The default DNS hash table size, - * Use a prime number happy with hash table. - */ - private static final int DEFAULT_CACHE_SIZE = 89; - - /** - * The default caching period in minutes. - */ - private static final int DEFAULT_CACHE_PERIOD = 4 * 60; - - /** - * Percentage of cache entries to purge when the table gets full. - */ - private static final int DEFAULT_CACHE_PURGE_PCT = 30; - - /** * The special IP address INADDR_ANY. */ private static InetAddress inaddr_any; @@ -96,50 +79,8 @@ public class InetAddress implements Serializable */ static InetAddress LOCALHOST; - /** - * The size of the cache. - */ - private static int cache_size = 0; - - /** - * The length of time we will continue to read the address from cache - * before forcing another lookup. - */ - private static int cache_period = 0; - - /** - * What percentage of the cache we will purge if it gets full. - */ - private static int cache_purge_pct = 0; - - /** - * HashMap to use as DNS lookup cache. - * Use HashMap because all accesses to cache are already synchronized. - */ - private static HashMap cache; - static { - // Look for properties that override default caching behavior - cache_size = - Integer.getInteger("gnu.java.net.dns_cache_size", DEFAULT_CACHE_SIZE) - .intValue(); - cache_period = - Integer.getInteger("gnu.java.net.dns_cache_period", - DEFAULT_CACHE_PERIOD * 60 * 1000).intValue(); - - cache_purge_pct = - Integer.getInteger("gnu.java.net.dns_cache_purge_pct", - DEFAULT_CACHE_PURGE_PCT).intValue(); - - // Fallback to defaults if necessary - if ((cache_purge_pct < 1) || (cache_purge_pct > 100)) - cache_purge_pct = DEFAULT_CACHE_PURGE_PCT; - - // Create the cache - if (cache_size != 0) - cache = new HashMap(cache_size); - // precompute the ANY_IF address try { @@ -174,11 +115,6 @@ public class InetAddress implements Serializable String hostName; /** - * The time this address was looked up. - */ - transient long lookup_time; - - /** * The field 'family' seems to be the AF_ value. * FIXME: Much of the code in the other java.net classes does not make * use of this family field. A better implementation would be to make @@ -200,8 +136,6 @@ public class InetAddress implements Serializable addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone(); hostName = hostname; - lookup_time = System.currentTimeMillis(); - family = 2; /* AF_INET */ } @@ -649,20 +583,17 @@ public class InetAddress implements Serializable InetAddress[] addresses; + if (hostname != null) + hostname = hostname.trim(); + // Default to current host if necessary - if (hostname == null) + if (hostname == null || hostname.equals("")) { addresses = new InetAddress[1]; addresses[0] = LOCALHOST; return addresses; } - // Check the cache for this host before doing a lookup - addresses = checkCacheFor(hostname); - - if (addresses != null) - return addresses; - // Not in cache, try the lookup byte[][] iplist = VMInetAddress.getHostByName(hostname); @@ -679,71 +610,10 @@ public class InetAddress implements Serializable addresses[i] = new Inet4Address(iplist[i], hostname); } - addToCache(hostname, addresses); return addresses; } /** - * This method checks the DNS cache to see if we have looked this hostname - * up before. If so, we return the cached addresses unless it has been in the - * cache too long. - * - * @param hostname The hostname to check for - * - * @return The InetAddress for this hostname or null if not available - */ - private static synchronized InetAddress[] checkCacheFor(String hostname) - { - InetAddress[] addresses = null; - - if (cache_size == 0) - return null; - - Object obj = cache.get(hostname); - if (obj == null) - return null; - - if (obj instanceof InetAddress[]) - addresses = (InetAddress[]) obj; - - if (addresses == null) - return null; - - if (cache_period != -1) - if ((System.currentTimeMillis() - addresses[0].lookup_time) > cache_period) - { - cache.remove(hostname); - return null; - } - - return addresses; - } - - /** - * This method adds an InetAddress object to our DNS cache. Note that - * if the cache is full, then we run a purge to get rid of old entries. - * This will cause a performance hit, thus applications using lots of - * lookups should set the cache size to be very large. - * - * @param hostname The hostname to cache this address under - * @param obj The InetAddress or InetAddress array to store - */ - private static synchronized void addToCache(String hostname, Object obj) - { - if (cache_size == 0) - return; - - // Check to see if hash table is full - if (cache_size != -1) - if (cache.size() == cache_size) - { - // FIXME Add code to purge later. - } - - cache.put(hostname, obj); - } - - /** * Returns the special address INADDR_ANY used for binding to a local * port on all IP addresses hosted by a the local host. * @@ -757,6 +627,7 @@ public class InetAddress implements Serializable { byte[] tmp = VMInetAddress.lookupInaddrAny(); inaddr_any = new Inet4Address(tmp, null); + inaddr_any.hostName = inaddr_any.getHostName(); } return inaddr_any; diff --git a/libjava/classpath/java/net/URL.java b/libjava/classpath/java/net/URL.java index 1d947a0b46a..168c67a19ee 100644 --- a/libjava/classpath/java/net/URL.java +++ b/libjava/classpath/java/net/URL.java @@ -1,5 +1,5 @@ /* URL.java -- Uniform Resource Locator Class - Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,7 @@ exception statement from your version. */ package java.net; +import gnu.classpath.SystemProperties; import gnu.java.net.URLParseError; import java.io.IOException; @@ -198,7 +199,7 @@ public final class URL implements Serializable static { - String s = System.getProperty("gnu.java.net.nocache_protocol_handlers"); + String s = SystemProperties.getProperty("gnu.java.net.nocache_protocol_handlers"); if (s == null) cache_handlers = true; @@ -342,7 +343,7 @@ public final class URL implements Serializable */ public URL(URL context, String spec) throws MalformedURLException { - this(context, spec, (URLStreamHandler) null); + this(context, spec, (context == null) ? (URLStreamHandler)null : context.ph); } /** @@ -867,7 +868,7 @@ public final class URL implements Serializable // Except in very unusual environments the JDK specified one shouldn't // ever be needed (or available). String ph_search_path = - System.getProperty("java.protocol.handler.pkgs"); + SystemProperties.getProperty("java.protocol.handler.pkgs"); // Tack our default package on at the ends. if (ph_search_path != null) |