diff options
author | Michael Koch <konqueror@gmx.de> | 2003-10-02 15:17:13 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-10-02 15:17:13 +0000 |
commit | 484fe3bff87b2285ae4ae70047fa9cb76d64ee7e (patch) | |
tree | 684fb0979b64b364506bb3931e9a87d0093c77e2 /libjava | |
parent | b97e92ed3a4dd394c2d764c3a78264f43050a35e (diff) | |
download | gcc-484fe3bff87b2285ae4ae70047fa9cb76d64ee7e.zip gcc-484fe3bff87b2285ae4ae70047fa9cb76d64ee7e.tar.gz gcc-484fe3bff87b2285ae4ae70047fa9cb76d64ee7e.tar.bz2 |
2003-10-02 Michael Koch <konqueror@gmx.de>
* java/net/InetAddress.java
(zeros): Removed.
(ANY_IF): Initalizie in static block.
(static): Load library with native methods here and initialize ANY_IF.
(isAnyLocalAddress): Check if equal to ANY_IF.
(equals): Use addr directly instead of addr1. Simplify for loop.
(toString): Rename "result" to "host" and add IP address allways.
(getLocalHost): Merged documentation from classpath.
* java/net/ServerSocket.java
(ServerSocket): New package-private constructor used by java.nio.
* java/net/URLConnection.java
(getRequestProperties): Check if already connected.
From-SVN: r72032
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 15 | ||||
-rw-r--r-- | libjava/java/net/InetAddress.java | 39 | ||||
-rw-r--r-- | libjava/java/net/ServerSocket.java | 14 | ||||
-rw-r--r-- | libjava/java/net/URLConnection.java | 10 |
4 files changed, 60 insertions, 18 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 4b7406f..42ea207 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,20 @@ 2003-10-02 Michael Koch <konqueror@gmx.de> + * java/net/InetAddress.java + (zeros): Removed. + (ANY_IF): Initalizie in static block. + (static): Load library with native methods here and initialize ANY_IF. + (isAnyLocalAddress): Check if equal to ANY_IF. + (equals): Use addr directly instead of addr1. Simplify for loop. + (toString): Rename "result" to "host" and add IP address allways. + (getLocalHost): Merged documentation from classpath. + * java/net/ServerSocket.java + (ServerSocket): New package-private constructor used by java.nio. + * java/net/URLConnection.java + (getRequestProperties): Check if already connected. + +2003-10-02 Michael Koch <konqueror@gmx.de> + * java/nio/ByteBufferHelper.java: Rewrote all methods by suggestions from Eric Blake. diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java index bb82994..6d72d62 100644 --- a/libjava/java/net/InetAddress.java +++ b/libjava/java/net/InetAddress.java @@ -38,6 +38,7 @@ exception statement from your version. */ package java.net; +import gnu.classpath.Configuration; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -63,17 +64,27 @@ public class InetAddress implements Serializable { private static final long serialVersionUID = 3286316764910316507L; - static final byte[] zeros = { 0, 0, 0, 0 }; - /** * Dummy InetAddress, used to bind socket to any (all) network interfaces. */ - static final InetAddress ANY_IF = new InetAddress (zeros, null); + static InetAddress ANY_IF; private static final byte[] localhostAddress = { 127, 0, 0, 1 }; private static InetAddress localhost = null; + static + { + // load the shared library needed for name resolution + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary ("javanet"); + } + + byte[] zeros = { 0, 0, 0, 0 }; + ANY_IF = new InetAddress (zeros, null); + } + /** * The Serialized Form specifies that an int 'address' is saved/restored. * This class uses a byte array internally so we'll just do the conversion @@ -160,7 +171,7 @@ public class InetAddress implements Serializable { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - return addr == zeros; + return equals (ANY_IF); } /** @@ -475,14 +486,13 @@ public class InetAddress implements Serializable // different host names." This violates the description in the // JDK 1.2 API documentation. A little experimentation // shows that the latter is correct. - byte[] addr1 = addr; byte[] addr2 = ((InetAddress) obj).addr; - if (addr1.length != addr2.length) + if (addr.length != addr2.length) return false; - for (int i = addr1.length; --i >= 0; ) - if (addr1[i] != addr2[i]) + for (int i = 0; i < addr.length; i++) + if (addr [i] != addr2 [i]) return false; return true; @@ -497,15 +507,15 @@ public class InetAddress implements Serializable */ public String toString() { - String result; + String host; String address = getHostAddress(); if (hostName != null) - result = hostName + "/" + address; + host = hostName; else - result = address; + host = address; - return result; + return host + "/" + address; } /** @@ -656,7 +666,10 @@ public class InetAddress implements Serializable private static native String getLocalHostname(); /** - * Returns the local host address. + * Returns an InetAddress object representing the address of the current + * host. + * + * @return The local host's address * * @exception UnknownHostException If no IP address for the host could * be found diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java index 4428178..6b5544b 100644 --- a/libjava/java/net/ServerSocket.java +++ b/libjava/java/net/ServerSocket.java @@ -74,6 +74,17 @@ public class ServerSocket private SocketImpl impl; private boolean closed = false; + + /* + * This is only used by java.nio. + */ + // FIXME: Workaround a bug in gcj. + //ServerSocket (PlainSocketImpl impl) throws IOException + ServerSocket (SocketImpl impl) throws IOException + { + this.impl = impl; + this.impl.create (true); + } /** * Constructor that simply sets the implementation. @@ -318,8 +329,7 @@ public class ServerSocket */ public void close () throws IOException { - if (impl != null) - impl.close (); + impl.close (); if (getChannel() != null) getChannel().close (); diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java index 5c43a7c..e39e578 100644 --- a/libjava/java/net/URLConnection.java +++ b/libjava/java/net/URLConnection.java @@ -1,5 +1,5 @@ /* URLConnection.java -- Abstract superclass for reading from URL's - Copyright (C) 1998, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,9 +45,10 @@ import java.security.Permission; import java.security.AllPermission; import java.text.ParsePosition; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; -import java.util.Locale; import java.util.Hashtable; +import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; import gnu.gcj.io.MimeTypes; @@ -783,9 +784,12 @@ public abstract class URLConnection */ public Map getRequestProperties() { + if (connected) + throw new IllegalStateException ("Already connected"); + // Overridden by subclasses that support reading header fields from the // request. - return null; + return Collections.EMPTY_MAP; } /** |