2003-03-02 Michael Koch <konqueror@gmx.de>
authorMichael Koch <konqueror@gmx.de>
Sun, 2 Mar 2003 13:50:04 +0000 (13:50 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Sun, 2 Mar 2003 13:50:04 +0000 (13:50 +0000)
* 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

libjava/ChangeLog
libjava/java/net/DatagramSocket.java

index f4aca75d329eb419069817a50ae7cf499051a331..6d91983d0ad8c08477673b70038c3d2ceaf14578 100644 (file)
@@ -1,3 +1,13 @@
+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.
+       
 2003-03-02  Michael Koch  <konqueror@gmx.de>
 
        * configure.in: Added check for memory mapping of files.
index 334083a6f354de146adbae6b3b60e25b5dcf6a49..091ebf98d1abc5eb121c87363004ed275c9af83f 100644 (file)
@@ -88,6 +88,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
    *
@@ -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;
   }
 
   /**