This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] java.net.DatagramSocket


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


Here a patch to fix some things in DatagramSocket.
Please review and comment.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+XgS4WSOgCCdjSDsRArJsAKCebLT6lbWoI7PwMbbY7MqYYGAqQQCfSrW1
rBYxvMTYBZeJqRpyDFkp/N0=
=CdI9
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1735
diff -u -r1.1735 ChangeLog
--- ChangeLog	27 Feb 2003 10:52:39 -0000	1.1735
+++ ChangeLog	27 Feb 2003 12:28:00 -0000
@@ -1,5 +1,15 @@
 2003-02-27  Michael Koch  <konqueror at gmx dot 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-02-27  Michael Koch  <konqueror at gmx dot de>
+
 	* java/beans/Beans.java,
 	java/beans/FeatureDescriptor.java
 	java/beans/PropertyEditorManager.java:
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.19
diff -u -r1.19 DatagramSocket.java
--- java/net/DatagramSocket.java	17 Feb 2003 15:33:54 -0000	1.19
+++ java/net/DatagramSocket.java	27 Feb 2003 12:28:00 -0000
@@ -89,6 +89,11 @@
   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 void close()
   {
-    impl.close();
-    remoteAddress = null;
-    remotePort = -1;
+    if (!closed)
+      {
+        impl.close();
+        remoteAddress = null;
+        remotePort = -1;
+        closed = true;
+      }
   }
 
   /**
@@ -217,9 +226,6 @@
    */
   public InetAddress getInetAddress()
   {
-    if (!isConnected ())
-      return null;
-
     return remoteAddress;
   }
 
@@ -234,9 +240,6 @@
    */
   public int getPort()
   {
-    if (!isConnected ())
-      return -1;
-    
     return remotePort;
   }
 
@@ -265,7 +268,7 @@
     //   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,12 @@
 
     try
       {
-	return InetAddress.getLocalHost();
+        return InetAddress.getLocalHost();
       }
     catch (UnknownHostException ex)
       {
-	// FIXME: This should never happen, so how can we avoid this construct?
-	return null;
+        // FIXME: This should never happen, so how can we avoid this construct?
+        return null;
       }
   }
 
@@ -469,7 +472,7 @@
 
   /**
    * 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 +480,8 @@
   public void disconnect()
   {
     impl.disconnect();
+    remoteAddress = null;
+    remotePort = -1;
   }
 
   /**
@@ -596,7 +601,7 @@
    */
   public boolean isClosed()
   {
-    return !impl.getFileDescriptor().valid();
+    return closed;
   }
 
   /**

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]