This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Patch: java.net.DatagramSocket
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 26 Nov 2003 15:54:42 +0100
- Subject: FYI: Patch: java.net.DatagramSocket
Hi list,
I commited the attached patch to move the binding code from the
DatagramSocket constructor to the bind() method.
Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2365
diff -u -b -B -r1.2365 ChangeLog
--- ChangeLog 26 Nov 2003 14:33:40 -0000 1.2365
+++ ChangeLog 26 Nov 2003 14:49:29 -0000
@@ -1,6 +1,12 @@
2003-11-26 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
+ (DategramSocket, bind): Moved binding code from DatagramSocket
+ constructor to bind method.
+
+2003-11-26 Michael Koch <konqueror@gmx.de>
+
+ * java/net/DatagramSocket.java
(impl): Made private.
(bound): New private member variable.
(DatagramSocket): Fixed documentation, use getImpl().
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.32
diff -u -b -B -r1.32 DatagramSocket.java
--- java/net/DatagramSocket.java 26 Nov 2003 14:33:41 -0000 1.32
+++ java/net/DatagramSocket.java 26 Nov 2003 14:49:29 -0000
@@ -187,44 +187,8 @@
impl = new PlainDatagramSocketImpl();
}
- 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
- {
- getImpl().bind(port, addr);
- }
- catch (SocketException exception)
- {
- getImpl().close();
- throw exception;
- }
- catch (RuntimeException exception)
- {
- getImpl().close();
- throw exception;
- }
- catch (Error error)
- {
- getImpl().close();
- throw error;
- }
+ if (address != null)
+ bind(address);
}
// This needs to be accessible from java.net.MulticastSocket
@@ -671,14 +635,39 @@
if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
- InetSocketAddress tmp = (InetSocketAddress) address;
+ 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(tmp.getPort ());
+ s.checkListen(port);
+
+ if (addr == null)
+ addr = InetAddress.ANY_IF;
- getImpl().bind (tmp.getPort (), tmp.getAddress ());
+ try
+ {
+ getImpl().bind(port, addr);
bound = true;
+ }
+ catch (SocketException exception)
+ {
+ getImpl().close();
+ throw exception;
+ }
+ catch (RuntimeException exception)
+ {
+ getImpl().close();
+ throw exception;
+ }
+ catch (Error error)
+ {
+ getImpl().close();
+ throw error;
+ }
}
/**