summaryrefslogtreecommitdiff
path: root/libjava/java/net/DatagramSocket.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-11-24 23:00:07 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-11-24 23:00:07 +0000
commit473432eb026530ae681374368552bfe0579273b6 (patch)
treecb7cfa884411e2b3f061ad5ba401cee5fd2579bf /libjava/java/net/DatagramSocket.java
parent4c1bbd67f92676cc59d8ab173a12f14288d676fd (diff)
2003-11-25 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java (DatagramSocket): Move binding code to bind(), simplify constructors. * java/net/MulticastSocket.java (MulticastSocket): Call parent constructor with null argument, bind socket after setReuseAddress is called, simplify constructors. From-SVN: r73902
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
-rw-r--r--libjava/java/net/DatagramSocket.java74
1 files changed, 41 insertions, 33 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
index 1d89d688401..59344455e27 100644
--- a/libjava/java/net/DatagramSocket.java
+++ b/libjava/java/net/DatagramSocket.java
@@ -138,21 +138,32 @@ public class DatagramSocket
* the specified local port and address.
*
* @param port The local port number to bind to.
- * @param laddr The local address to bind to.
+ * @param addr The local address to bind to.
*
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation.
* @exception SocketException If an error occurs.
*/
- public DatagramSocket(int port, InetAddress laddr) throws SocketException
+ public DatagramSocket(int port, InetAddress addr) throws SocketException
{
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Invalid port: " + port);
-
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkListen(port);
+ this(new InetSocketAddress(addr, port));
+ }
+ /**
+ * Initializes a new instance of <code>DatagramSocket</code> that binds to
+ * the specified local port and address.
+ *
+ * @param port The local port number to bind to.
+ * @param laddr The local address to bind to.
+ *
+ * @exception SecurityException If a security manager exists and its
+ * <code>checkListen</code> method doesn't allow the operation.
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.4
+ */
+ public DatagramSocket (SocketAddress address) throws SocketException
+ {
String propVal = System.getProperty("impl.prefix");
if (propVal == null || propVal.equals(""))
impl = new PlainDatagramSocketImpl();
@@ -170,48 +181,45 @@ public class DatagramSocket
}
impl.create();
- if (laddr == null)
- laddr = InetAddress.ANY_IF;
+ if (address == null)
+ return;
+
+ if (! (address instanceof InetSocketAddress))
+ throw new SocketException("unsupported address type");
+
+ InetAddress addr = ((InetSocketAddress) address).getAddress();
+ int port = ((InetSocketAddress) address).getPort();
+
+ if (port < 0 || port > 65535)
+ throw new IllegalArgumentException("Invalid port: " + port);
+
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkListen(port);
+
+ if (addr == null)
+ addr = InetAddress.ANY_IF;
try
{
- impl.bind (port, laddr);
+ impl.bind(port, addr);
}
catch (SocketException exception)
{
- impl.close ();
+ impl.close();
throw exception;
}
catch (RuntimeException exception)
{
- impl.close ();
+ impl.close();
throw exception;
}
catch (Error error)
{
- impl.close ();
+ impl.close();
throw error;
}
}
-
- /**
- * Initializes a new instance of <code>DatagramSocket</code> that binds to
- * the specified local port and address.
- *
- * @param port The local port number to bind to.
- * @param laddr The local address to bind to.
- *
- * @exception SecurityException If a security manager exists and its
- * <code>checkListen</code> method doesn't allow the operation.
- * @exception SocketException If an error occurs.
- *
- * @since 1.4
- */
- public DatagramSocket (SocketAddress address) throws SocketException
- {
- this (((InetSocketAddress) address).getPort (),
- ((InetSocketAddress) address).getAddress ());
- }
/**
* Closes this datagram socket.