Spawn.vala
[gitlive] / Spawn.vala
index 4291953..92f9259 100644 (file)
@@ -1,10 +1,10 @@
 
+/// # valac  --pkg gio-2.0 --pkg gtk+-3.0  --pkg posix Spawn.vala -o /tmp/Spawn
 
 using GLib;
 using Gtk;
 // compile valac 
 
-/// # valac  --pkg gio-2.0  --pkg posix Spawn.vala -o /tmp/Spawn
 
 
 ///using Gee; // for array list?
@@ -144,7 +144,7 @@ public class Spawn : Object
     }
 
     
-    bool ctx = false; // the mainloop ctx.
+    MainLoop ctx = null; // the mainloop ctx.
     
     /**
      * @property output {String} resulting output
@@ -241,8 +241,9 @@ public class Spawn : Object
             
             Process.close_pid(this.pid);
             this.pid = -1;
-            if (this.ctx) {
+            if (this.ctx != null) {
                 this.ctx.quit();
+                this.ctx = null;
             }
             this.tidyup();
         //print("DONE TIDYUP");
@@ -345,16 +346,20 @@ public class Spawn : Object
             Process.close_pid(this.pid); // hopefully kills it..
             this.pid = -1;
         }
-        if (this.in_ch)  this.in_ch.close();
-        if (this.out_ch)  this.out_ch.close();
-        if (this.err_ch)  this.err_ch.close();
+        try {
+            if (this.in_ch != null)  this.in_ch.shutdown(true);
+            if (this.out_ch != null)  this.out_ch.shutdown(true);
+            if (this.err_ch != null)  this.err_ch.shutdown(true);
+        } catch (Error e) {
+            // error shutting donw.
+        }
         // blank out channels
-        this.in_ch = false;
-        this.err_ch = false;
-        this.out_ch = false;
+        this.in_ch = null;
+        this.err_ch = null;
+        this.out_ch = null;
         // rmeove listeners !! important otherwise we kill the CPU
-        if (this.err_src > -1 ) GLib.source_remove(this.err_src);
-        if (this.out_src > -1 ) GLib.source_remove(this.out_src);
+        //if (this.err_src > -1 ) GLib.source_remove(this.err_src);
+        //if (this.out_src > -1 ) GLib.source_remove(this.out_src);
         this.err_src = -1;
         this.out_src = -1;