diff options
author | Michael Koch <konqueror@gmx.de> | 2003-03-02 13:50:04 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-03-02 13:50:04 +0000 |
commit | 37db829b936aa6483eff60a7522e34ad6dcecb79 (patch) | |
tree | 2ae3db7de7caf56b5219765da4466addb984cb74 /libjava/java/net | |
parent | c0daa902837561b1c114bdee9e8cee5f8797e610 (diff) | |
download | gcc-37db829b936aa6483eff60a7522e34ad6dcecb79.zip gcc-37db829b936aa6483eff60a7522e34ad6dcecb79.tar.gz gcc-37db829b936aa6483eff60a7522e34ad6dcecb79.tar.bz2 |
2003-03-02 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(closed): New member variable.
(close): Use closed variable.
(getInetAddress): No need to call isConnected().
(getPort): No need to call isConnected().
(disconnect): Reset remoteAddress and remotePort, fixed typo.
(isClosed): Reimplemented.
From-SVN: r63662
Diffstat (limited to 'libjava/java/net')
-rw-r--r-- | libjava/java/net/DatagramSocket.java | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index 334083a..091ebf9 100644 --- a/libjava/java/net/DatagramSocket.java +++ b/libjava/java/net/DatagramSocket.java @@ -89,6 +89,11 @@ public class DatagramSocket private int remotePort = -1; /** + * Indicates when the socket is closed. + */ + private boolean closed = false; + + /** * Creates a DatagramSocket from a specified DatagramSocketImpl instance * * @param impl The DatagramSocketImpl the socket will be created from @@ -201,9 +206,13 @@ public class DatagramSocket */ public void close() { - impl.close(); - remoteAddress = null; - remotePort = -1; + if (!closed) + { + impl.close(); + remoteAddress = null; + remotePort = -1; + closed = true; + } } /** @@ -217,9 +226,6 @@ public class DatagramSocket */ public InetAddress getInetAddress() { - if (!isConnected ()) - return null; - return remoteAddress; } @@ -234,9 +240,6 @@ public class DatagramSocket */ public int getPort() { - if (!isConnected ()) - return -1; - return remotePort; } @@ -265,7 +268,7 @@ public class DatagramSocket // s.checkConnect("localhost", -1); try { - return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR); + return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR); } catch (SocketException ex) { @@ -273,12 +276,11 @@ public class DatagramSocket try { - return InetAddress.getLocalHost(); + return InetAddress.getLocalHost(); } catch (UnknownHostException ex) { - // FIXME: This should never happen, so how can we avoid this construct? - return null; + return null; } } @@ -469,7 +471,7 @@ public class DatagramSocket /** * This method disconnects this socket from the address/port it was - * conencted to. If the socket was not connected in the first place, + * connected to. If the socket was not connected in the first place, * this method does nothing. * * @since 1.2 @@ -477,6 +479,8 @@ public class DatagramSocket public void disconnect() { impl.disconnect(); + remoteAddress = null; + remotePort = -1; } /** @@ -596,7 +600,7 @@ public class DatagramSocket */ public boolean isClosed() { - return !impl.getFileDescriptor().valid(); + return closed; } /** |