[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] DatagramSocket constrcutor fixes
From: |
Dalibor Topic |
Subject: |
[PATCH] DatagramSocket constrcutor fixes |
Date: |
Fri, 21 Nov 2003 19:00:10 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 |
Hi all,
attached is another patch from Guilhem that fixes DatagramSocket
constructor behaviour & comments. It resulted as a fix to a bug report
to the kaffe mailing list from Everton da Silva Marques [1]. Please also
take a look at the discussion in the thread about other approaches to
fix the issue, and why they weren't picked.
2003-11-21 Guilhem Lavaux <address@hidden>
* libraries/javalib/java/net/DatagramSocket.java
((DatagramSocket(SocketAddress)): Fixed comment to match
method. If address is null leave socket unbound.
(DatagramSocket(int, InetAddress)): Rewritten to delegate
to ((DatagramSocket(SocketAddress)) in order to pick up
the fix. Moved checking code into
((DatagramSocket(SocketAddress)).
cheers,
dalibor topic
[1] http://www.mail-archive.com/address@hidden/msg03573.html
--- /var/tmp/PROJECTS/classpath//./java/net/DatagramSocket.java Mon Sep 22
16:56:08 2003
+++ /tmp/topic/kaffe/libraries/javalib/java/net/DatagramSocket.java Mon Nov
3 18:24:43 2003
@@ -146,13 +146,24 @@
*/
public DatagramSocket(int port, InetAddress laddr) 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 (laddr, port));
+ }
+ /**
+ * Initializes a new instance of <code>DatagramSocket</code> that binds to
+ * the specified local port and address.
+ *
+ * @param address address to bind the socket to. If address is null,
+ * the socket is left unbound.
+ *
+ * @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,12 +181,26 @@
}
impl.create();
+ // If address is null just return immediately.
+ if (address == null)
+ return;
+
+ InetSocketAddress is_addr = (InetSocketAddress)address;
+ InetAddress laddr;
+
+ laddr = is_addr.getAddress();
if (laddr == null)
laddr = InetAddress.ANY_IF;
-
+ if (is_addr.getPort() < 0 || is_addr.getPort() > 65535)
+ throw new IllegalArgumentException("Invalid port: " + is_addr.getPort());
+
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkListen (is_addr.getPort());
+
try
{
- impl.bind (port, laddr);
+ impl.bind (is_addr.getPort(), laddr);
}
catch (SocketException exception)
{
@@ -193,25 +218,6 @@
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.
- [PATCH] DatagramSocket constrcutor fixes,
Dalibor Topic <=