Commit 7d8f4ff9 by Michael Koch Committed by Michael Koch

2003-06-17 Michael Koch <konqueror@gmx.de>

	* java/net/InetSocketAddress.java
	(InetSocketAddress): Use wildcard address if addr is null.
	(InetSocketAddress): Dont duplicate implementation.
	(InetSocketAddress): Throw exception when hostname is null.
	* java/net/Socket.java:
	Reworked imports.
	(Socket): Throw exception when raddr is null, handle case when laddr
	is null.

From-SVN: r68106
parent 6f3aed57
2003-06-17 Michael Koch <konqueror@gmx.de> 2003-06-17 Michael Koch <konqueror@gmx.de>
* java/net/InetSocketAddress.java
(InetSocketAddress): Use wildcard address if addr is null.
(InetSocketAddress): Dont duplicate implementation.
(InetSocketAddress): Throw exception when hostname is null.
* java/net/Socket.java:
Reworked imports.
(Socket): Throw exception when raddr is null, handle case when laddr
is null.
2003-06-17 Michael Koch <konqueror@gmx.de>
* java/nio/DirectByteBufferImpl.java * java/nio/DirectByteBufferImpl.java
(address): Made package private. (address): Made package private.
(DirectByteBufferImpl): New constructor. (DirectByteBufferImpl): New constructor.
......
...@@ -69,6 +69,9 @@ public class InetSocketAddress extends SocketAddress ...@@ -69,6 +69,9 @@ public class InetSocketAddress extends SocketAddress
{ {
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (addr == null)
addr = InetAddress.ANY_IF;
this.addr = addr; this.addr = addr;
this.port = port; this.port = port;
...@@ -85,25 +88,9 @@ public class InetSocketAddress extends SocketAddress ...@@ -85,25 +88,9 @@ public class InetSocketAddress extends SocketAddress
public InetSocketAddress(int port) public InetSocketAddress(int port)
throws IllegalArgumentException throws IllegalArgumentException
{ {
if (port < 0 || port > 65535) this ((InetAddress) null, port);
throw new IllegalArgumentException();
this.port = port;
try
{
byte[] any = { 0, 0, 0, 0 };
this.addr = InetAddress.getByAddress (any);
this.hostname = "0.0.0.0";
}
catch (UnknownHostException e)
{
this.addr = null;
this.hostname = "";
}
} }
/** /**
* Constructs an InetSocketAddress instance. * Constructs an InetSocketAddress instance.
* *
...@@ -115,7 +102,8 @@ public class InetSocketAddress extends SocketAddress ...@@ -115,7 +102,8 @@ public class InetSocketAddress extends SocketAddress
public InetSocketAddress(String hostname, int port) public InetSocketAddress(String hostname, int port)
throws IllegalArgumentException throws IllegalArgumentException
{ {
if (port < 0 || port > 65535) if (port < 0 || port > 65535
|| hostname == null)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
this.port = port; this.port = port;
......
...@@ -37,7 +37,9 @@ exception statement from your version. */ ...@@ -37,7 +37,9 @@ exception statement from your version. */
package java.net; package java.net;
import java.io.*; import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.IllegalBlockingModeException;
...@@ -87,8 +89,6 @@ public class Socket ...@@ -87,8 +89,6 @@ public class Socket
private boolean closed = false; private boolean closed = false;
// Constructors
/** /**
* Initializes a new instance of <code>Socket</code> object without * Initializes a new instance of <code>Socket</code> object without
* connecting to a remote host. This useful for subclasses of socket that * connecting to a remote host. This useful for subclasses of socket that
...@@ -282,6 +282,9 @@ public class Socket ...@@ -282,6 +282,9 @@ public class Socket
{ {
this(); this();
if (raddr == null)
throw new NullPointerException ();
if (impl == null) if (impl == null)
throw new IOException("Cannot initialize Socket implementation"); throw new IOException("Cannot initialize Socket implementation");
...@@ -289,8 +292,12 @@ public class Socket ...@@ -289,8 +292,12 @@ public class Socket
if (sm != null) if (sm != null)
sm.checkConnect(raddr.getHostName(), rport); sm.checkConnect(raddr.getHostName(), rport);
// bind/connect socket // bind socket
bind (new InetSocketAddress (laddr, lport)); SocketAddress bindaddr =
laddr == null ? null : new InetSocketAddress (laddr, lport);
bind (bindaddr);
// connect socket
connect (new InetSocketAddress (raddr, rport)); connect (new InetSocketAddress (raddr, rport));
// FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port, // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
......
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