summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Frijters <jeroen@sumatra.nl>2006-09-24 15:49:47 +0000
committerJeroen Frijters <jeroen@sumatra.nl>2006-09-24 15:49:47 +0000
commit2b0d32f81cd57cd975dc7083806178bac025119c (patch)
treedc76a79b703d5eae128efefe85b4ce92ed59e636
parentff6336ac55138f91793befedda6b6c248cccd3df (diff)
downloadclasspath-2b0d32f81cd57cd975dc7083806178bac025119c.tar.gz
2006-09-24 Jeroen Frijters <jeroen@frijters.net>
* java/net/ServerSocket.java (bind(SocketAddress,int)): Added support for null address. Throw proper exception if already bound. Handle unresolved addresses correctly. Ignore exceptions that happen during close in error path (to prevent losing the original exception.)
-rw-r--r--ChangeLog9
-rw-r--r--java/net/ServerSocket.java59
2 files changed, 43 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 284d98d88..6e6fde47e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-09-24 Jeroen Frijters <jeroen@frijters.net>
+
+ * java/net/ServerSocket.java
+ (bind(SocketAddress,int)): Added support for null address.
+ Throw proper exception if already bound.
+ Handle unresolved addresses correctly. Ignore exceptions that
+ happen during close in error path (to prevent losing the original
+ exception.)
+
2006-09-24 Mark Wielaard <mark@klomp.org>
Suggested by Aaron M. Ucko <ucko@debian.org>
diff --git a/java/net/ServerSocket.java b/java/net/ServerSocket.java
index 116227f8f..533626e0b 100644
--- a/java/net/ServerSocket.java
+++ b/java/net/ServerSocket.java
@@ -221,44 +221,53 @@ public class ServerSocket
if (isClosed())
throw new SocketException("ServerSocket is closed");
- if (! (endpoint instanceof InetSocketAddress))
- throw new IllegalArgumentException("Address type not supported");
+ if (isBound())
+ throw new SocketException("Already bound");
- InetSocketAddress tmp = (InetSocketAddress) endpoint;
+ InetAddress addr;
+ int port;
+
+ if (endpoint == null)
+ {
+ addr = InetAddress.ANY_IF;
+ port = 0;
+ }
+ else if (! (endpoint instanceof InetSocketAddress))
+ {
+ throw new IllegalArgumentException("Address type not supported");
+ }
+ else
+ {
+ InetSocketAddress tmp = (InetSocketAddress) endpoint;
+ if (tmp.isUnresolved())
+ throw new SocketException("Unresolved address");
+ addr = tmp.getAddress();
+ port = tmp.getPort();
+ }
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkListen(tmp.getPort());
-
- InetAddress addr = tmp.getAddress();
-
- // Initialize addr with 0.0.0.0.
- if (addr == null)
- addr = InetAddress.ANY_IF;
+ s.checkListen(port);
try
{
- port = tmp.getPort();
impl.bind(addr, port);
impl.listen(backlog);
- local = new InetSocketAddress(
+ this.port = port;
+ local = new InetSocketAddress(
(InetAddress) impl.getOption(SocketOptions.SO_BINDADDR),
impl.getLocalPort());
}
- catch (IOException exception)
- {
- close();
- throw exception;
- }
- catch (RuntimeException exception)
- {
- close();
- throw exception;
- }
- catch (Error error)
+ finally
{
- close();
- throw error;
+ try
+ {
+ if (local == null)
+ close();
+ }
+ catch (IOException _)
+ {
+ }
}
}