Debug session thread and socket leak fixed:
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGProxy.java
index b28f529..0ba0723 100644 (file)
@@ -150,39 +150,33 @@ public class PHPDBGProxy {
     }
   }
 
-  private String MapPath(PHPLineBreakpoint phpLBP)
-  {
-       IPath filename;
-    if (remote)
-    {
-        filename = phpLBP.getMarker().getResource().getProjectRelativePath();
-               filename = remoteSourcePath.append(filename);
-    }
-      else
-        filename = phpLBP.getMarker().getResource().getLocation();
-    String path=filename.toOSString();
-    if(pathmap!=null&&remote)
-    {
-    java.util.Iterator i=pathmap.keySet().iterator();  
-       while(i.hasNext())
-       {
-               String k=(String)i.next();
-               if(path.substring(0,k.length()).equals(k))
-               {
-                       path=pathmap.get(k)+path.substring(k.length());
-                       break;
-               }
-       }
-    }
-       if(pathtranslation&&remote)
-       {
-               if(path.substring(0,1).equals("/"))
-                       path=path.replace('\\','/');
-               else
-                       path=path.replace('/','\\');
+  private String MapPath(PHPLineBreakpoint phpLBP) {
+               IPath filename;
+               if (remote) {
+                       filename = phpLBP.getMarker().getResource()
+                                       .getProjectRelativePath();
+                       filename = remoteSourcePath.append(filename);
+               } else
+                       filename = phpLBP.getMarker().getResource().getLocation();
+               String path = filename.toOSString();
+               if (pathmap != null && remote) {
+                       java.util.Iterator i = pathmap.keySet().iterator();
+                       while (i.hasNext()) {
+                               String k = (String) i.next();
+                               if (path.startsWith(k)) {
+                                       path = pathmap.get(k) + path.substring(k.length());
+                                       break;
+                               }
+                       }
+               }
+               if (pathtranslation && remote) {
+                       if (path.substring(0, 1).equals("/"))
+                               path = path.replace('\\', '/');
+                       else
+                               path = path.replace('/', '\\');
+               }
+               return path;
        }
-    return path;
-  }
   
   public void addBreakpoint(IBreakpoint breakpoint) {
     if (DBGInt == null)
@@ -247,7 +241,12 @@ public class PHPDBGProxy {
 
   public void pause() {
     try {
-      DBGInt.pauseExecution();
+      if (null != DBGInt)
+       DBGInt.pauseExecution();
+      else {
+       // TODO Make sure the Suspend action is grayed out 
+       // when DBGInt is null
+      }
     } catch (IOException e) {
       PHPDebugCorePlugin.log(e);
       stop();
@@ -347,8 +346,17 @@ public class PHPDBGProxy {
     }
 
     public synchronized void setShouldStop() {
-      shouldStop = true;
-    }
+               shouldStop = true;
+               try {
+                       // If the loop thread is blocked on the server socket, 
+                       // forcibly unblock it to avoid leaking the thread, 
+                       // the socket and the port
+                       closeServerSocket();
+               } catch (IOException x) {
+                       // Log this as a warning?
+                       PHPDebugCorePlugin.log(x);
+               }
+       }
 
     public synchronized void notifyWait() {
       notify();
@@ -473,4 +481,4 @@ public class PHPDBGProxy {
       }
     }
   }
-}
\ No newline at end of file
+}