classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:Re: [cp-patches] FYI: Stability fix for gnu/CORBA/SocketRepository: P


From: Meskauskas Audrius
Subject: Re:Re: [cp-patches] FYI: Stability fix for gnu/CORBA/SocketRepository: Patch attached to fix this.
Date: Fri, 04 Nov 2005 22:32:03 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Thanks Mark for noticing the  synchronization bug.

Audrius.

2005-11-04  Audrius Meskauskas  <address@hidden>

       * gnu/CORBA/SocketRepository.java (sockets): Changed type to
   HashMap. (put_socket, get_socket, gc):
   Always synchronize on 'sockets'.

Index: gnu/CORBA/SocketRepository.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/SocketRepository.java,v
retrieving revision 1.4
diff -u -r1.4 SocketRepository.java
--- gnu/CORBA/SocketRepository.java     31 Oct 2005 11:24:18 -0000      1.4
+++ gnu/CORBA/SocketRepository.java     4 Nov 2005 21:24:14 -0000
@@ -40,7 +40,7 @@
 
 import java.net.Socket;
 import java.net.SocketException;
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -56,7 +56,7 @@
   /**
    * The socket map.
    */
-  private static Hashtable sockets = new Hashtable();
+  private static HashMap sockets = new HashMap();
   
   /**
    * Put a socket. This method also discards all not reusable sockets from
@@ -68,14 +68,18 @@
    */
   public static void put_socket(Object key, Socket s)
   {
-    sockets.put(key, s);
-    gc();
+    synchronized (sockets)
+      {
+        sockets.put(key, s);
+        gc();
+      }
   }
   
   /**
-   * Removes all non reusable sockets.
+   * Removes all non reusable sockets. As it is private,
+   * we know we call from the synchronized code already. 
    */
-  public static void gc()
+  private static void gc()
   {
     Iterator iter = sockets.entrySet().iterator();
     
@@ -107,38 +111,41 @@
    * @param key a socket key.
    * 
    * @return an opened socket for reuse, null if no such available or it is
-   * closed, its input or output has been shutown or otherwise the socket
-   * is not reuseable.
+   * closed, its input or output has been shutown or otherwise the socket is 
not
+   * reuseable.
    */
   public static Socket get_socket(Object key)
   {
     if (true)
       return null;
-    
-    Socket s = (Socket) sockets.get(key);
-    if (s == null)
-      return null;
-    
-    // Ensure that the socket is fully reusable.
-    else if (not_reusable(s))
-      {
-        sockets.remove(key);
-        return null;
-      }
-    else
+
+    synchronized (sockets)
       {
-        try
+        Socket s = (Socket) sockets.get(key);
+        if (s == null)
+          return null;
+
+        // Ensure that the socket is fully reusable.
+        else if (not_reusable(s))
           {
-            // Set one minute time out that will be changed later.
-            s.setSoTimeout(60*1000);
+            sockets.remove(key);
+            return null;
           }
-        catch (SocketException e)
+        else
           {
-            s = null;
+            try
+              {
+                // Set one minute time out that will be changed later.
+                s.setSoTimeout(60 * 1000);
+              }
+            catch (SocketException e)
+              {
+                s = null;
+              }
+
+            sockets.remove(key);
+            return s;
           }
-        
-        sockets.remove(key);
-        return s;
       }
   }
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]