Commit 473432eb by Michael Koch Committed by Michael Koch

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
parent 4c1bbd67
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.
2003-11-24 Michael Koch <konqueror@gmx.de> 2003-11-24 Michael Koch <konqueror@gmx.de>
* javax/swing/BoxLayout.java * javax/swing/BoxLayout.java
......
...@@ -138,21 +138,32 @@ public class DatagramSocket ...@@ -138,21 +138,32 @@ public class DatagramSocket
* the specified local port and address. * the specified local port and address.
* *
* @param port The local port number to bind to. * @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 * @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation. * checkListen method doesn't allow the operation.
* @exception SocketException If an error occurs. * @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) this(new InetSocketAddress(addr, port));
throw new IllegalArgumentException("Invalid port: " + port); }
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkListen(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"); String propVal = System.getProperty("impl.prefix");
if (propVal == null || propVal.equals("")) if (propVal == null || propVal.equals(""))
impl = new PlainDatagramSocketImpl(); impl = new PlainDatagramSocketImpl();
...@@ -170,48 +181,45 @@ public class DatagramSocket ...@@ -170,48 +181,45 @@ public class DatagramSocket
} }
impl.create(); impl.create();
if (laddr == null) if (address == null)
laddr = InetAddress.ANY_IF; 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 try
{ {
impl.bind (port, laddr); impl.bind(port, addr);
} }
catch (SocketException exception) catch (SocketException exception)
{ {
impl.close (); impl.close();
throw exception; throw exception;
} }
catch (RuntimeException exception) catch (RuntimeException exception)
{ {
impl.close (); impl.close();
throw exception; throw exception;
} }
catch (Error error) catch (Error error)
{ {
impl.close (); impl.close();
throw error; 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. * Closes this datagram socket.
......
...@@ -80,8 +80,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -80,8 +80,7 @@ public class MulticastSocket extends DatagramSocket
*/ */
public MulticastSocket() throws IOException public MulticastSocket() throws IOException
{ {
super(0, null); this(new InetSocketAddress(0));
setReuseAddress (true);
} }
/** /**
...@@ -95,8 +94,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -95,8 +94,7 @@ public class MulticastSocket extends DatagramSocket
*/ */
public MulticastSocket(int port) throws IOException public MulticastSocket(int port) throws IOException
{ {
super(port, null); this(new InetSocketAddress(port));
setReuseAddress (true);
} }
/** /**
...@@ -112,8 +110,10 @@ public class MulticastSocket extends DatagramSocket ...@@ -112,8 +110,10 @@ public class MulticastSocket extends DatagramSocket
*/ */
public MulticastSocket(SocketAddress address) throws IOException public MulticastSocket(SocketAddress address) throws IOException
{ {
super(address); super((SocketAddress) null);
setReuseAddress (true); setReuseAddress(true);
if (address != null)
bind(address);
} }
/** /**
......
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