Commit 484fe3bf by Michael Koch Committed by Michael Koch

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
parent b97e92ed
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.
......
......@@ -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
......
......@@ -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 ();
......
/* 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;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment