diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-11-26 14:50:27 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-11-26 14:50:27 +0000 |
commit | 1805cc52100b5f42b90ef461b017a8541e7e2d02 (patch) | |
tree | c8a53ad5b9d423e59467290138e06c01847f6a53 /libjava/java/net | |
parent | 8abe0aa880f7bca3e8ed049595ded6c4c6c017d2 (diff) | |
download | ppe42-gcc-1805cc52100b5f42b90ef461b017a8541e7e2d02.tar.gz ppe42-gcc-1805cc52100b5f42b90ef461b017a8541e7e2d02.zip |
2003-11-26 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(DategramSocket, bind): Moved binding code from DatagramSocket
constructor to bind method.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73952 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net')
-rw-r--r-- | libjava/java/net/DatagramSocket.java | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index df397bf7c61..f4bc4ea79d5 100644 --- a/libjava/java/net/DatagramSocket.java +++ b/libjava/java/net/DatagramSocket.java @@ -187,44 +187,8 @@ public class DatagramSocket 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 @@ public class DatagramSocket 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); - getImpl().bind (tmp.getPort (), tmp.getAddress ()); - bound = true; + if (addr == null) + addr = InetAddress.ANY_IF; + + 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; + } } /** |