[gnome-code-assistance] [backends/vala] Use streams instead of channels



commit 4ce604aed7e0da82639616191dccd6d1bdfd321f
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Dec 4 19:02:00 2013 +0100

    [backends/vala] Use streams instead of channels

 backends/vala/Makefile.am  |    1 +
 backends/vala/service.vala |   52 ++++++++++++++++++++++++-------------------
 configure.ac               |    2 +-
 3 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/backends/vala/Makefile.am b/backends/vala/Makefile.am
index cbc9948..a1b6e18 100644
--- a/backends/vala/Makefile.am
+++ b/backends/vala/Makefile.am
@@ -42,6 +42,7 @@ backends_vala_libvalashared_la_VALAFLAGS =    \
 backends_vala_vala_VALAFLAGS =                 \
        $(backends_vala_common_valaflags)       \
        --pkg libvalashared                     \
+       --pkg gio-unix-2.0                      \
        --vapidir backends/vala
 
 backends_vala_valahelper_VALAFLAGS =           \
diff --git a/backends/vala/service.vala b/backends/vala/service.vala
index f292d84..7f7c2cc 100644
--- a/backends/vala/service.vala
+++ b/backends/vala/service.vala
@@ -29,35 +29,33 @@ public class Service
                d_makefile = new MakefileIntegration();
        }
 
-       private char[] read_all(IOChannel f)
+       private uint8[] read_all(InputStream f)
        {
-               char[] buffer = new char[4096];
-               char[] ret = new char[4096];
+               uint8[] buffer = new uint8[4096];
+               uint8[] ret = new uint8[4096];
                ret.length = 0;
 
                while (true)
                {
-                       size_t n;
-                       IOStatus st;
+                       ssize_t n;
 
                        try
                        {
-                               st = f.read_chars(buffer, out n);
+                               n = f.read(buffer);
                        }
                        catch
                        {
-                               st = IOStatus.ERROR;
-                               n = 0;
+                               break;
                        }
 
-                       for (var i = 0; i < n; i++)
+                       if (n <= 0)
                        {
-                               ret += buffer[i];
+                               break;
                        }
 
-                       if (st == IOStatus.EOF || st == IOStatus.ERROR)
+                       for (var i = 0; i < n; i++)
                        {
-                               break;
+                               ret += buffer[i];
                        }
                }
 
@@ -74,7 +72,15 @@ public class Service
 
                try
                {
-                       Process.spawn_async_with_pipes(wd, argv, null, 0, null, out pid, out inp, out outp, 
null);
+                       Process.spawn_async_with_pipes(wd,
+                                                      argv,
+                                                      null,
+                                                      SpawnFlags.DO_NOT_REAP_CHILD,
+                                                      null,
+                                                      out pid,
+                                                      out inp,
+                                                      out outp,
+                                                      null);
                }
                catch (SpawnError e)
                {
@@ -82,10 +88,10 @@ public class Service
                        return Rpc.Reply();
                }
 
-               var outstr = new IOChannel.unix_new(outp);
-               var instr = new IOChannel.unix_new(inp);
+               var outstr = new UnixInputStream(outp, true);
+               var instr = new UnixOutputStream(inp, true);
 
-               char[] retb = new char[0];
+               uint8[] retb = new uint8[0];
 
                Thread<void*>? reader = null;
                Thread<void*>? writer = null;
@@ -103,7 +109,7 @@ public class Service
 
                        try
                        {
-                               outstr.shutdown(false);
+                               outstr.close();
                        } catch {}
                }
 
@@ -124,19 +130,19 @@ public class Service
                                };
 
                                Variant vv = cmd;
-                               char[] data = new char[(int)vv.get_size()];
+                               uint8[] data = new uint8[(int)vv.get_size()];
 
                                vv.store((void *)data);
 
                                try
                                {
                                        size_t n;
-                                       instr.write_chars(data, out n);
+                                       instr.write_all(data, out n);
                                } catch {}
 
                                try
                                {
-                                       instr.shutdown(true);
+                                       instr.close();
                                } catch {}
 
                                return null;
@@ -148,7 +154,7 @@ public class Service
 
                        try
                        {
-                               instr.shutdown(false);
+                               instr.close();
                        } catch {}
                }
 
@@ -171,8 +177,8 @@ public class Service
 
                try
                {
-                       outstr.shutdown(false);
-                       instr.shutdown(false);
+                       outstr.close();
+                       instr.close();
                } catch {}
 
                Rpc.Reply r = Rpc.Reply();
diff --git a/configure.ac b/configure.ac
index 75efaa1..fdaa5f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -396,7 +396,7 @@ AC_ARG_ENABLE([vala],
               [enable_vala=auto])
 
 BACKEND_VALA_LIBVALA_VERSIONS="libvala-0.24 libvala-0.22 libvala-0.20"
-BACKEND_VALA_MODULES="gobject-2.0 >= 2.36 glib-2.0 >= 2.36 gio-2.0 >= 2.36 gee-0.8"
+BACKEND_VALA_MODULES="gobject-2.0 >= 2.36 glib-2.0 >= 2.36 gio-2.0 >= 2.36 gee-0.8 gio-unix-2.0 >= 2.36"
 
 BACKEND_VALA_LIBVALA=
 for i in $BACKEND_VALA_LIBVALA_VERSIONS; do


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