[vala/0.38] gdbus: Fix missing declaration of _fd_list for async methods



commit 282c6c80bbb611416a5aaa7b607bdd1848b398be
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Mar 27 23:59:59 2018 +0200

    gdbus: Fix missing declaration of _fd_list for async methods
    
    https://bugzilla.gnome.org/show_bug.cgi?id=794566

 codegen/valagdbusclientmodule.vala   |    2 +-
 tests/Makefile.am                    |    1 +
 tests/dbus/filedescriptor-async.test |   99 ++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 4d9caa1..32a45de 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -563,6 +563,7 @@ public class Vala.GDBusClientModule : GDBusModule {
                bool uses_fd = dbus_method_uses_file_descriptor (m);
                if (uses_fd) {
                        cfile.add_include ("gio/gunixfdlist.h");
+                       ccode.add_declaration ("GUnixFDList*", new CCodeVariableDeclarator ("_fd_list"));
                }
 
                bool has_error_argument = (m.get_error_types ().size > 0);
@@ -769,7 +770,6 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                        if (uses_fd) {
                                ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", 
new CCodeConstant ("0")));
-                               ccode.add_declaration ("GUnixFDList*", new CCodeVariableDeclarator 
("_fd_list"));
                                ccode.add_declaration ("gint", new CCodeVariableDeclarator ("_fd"));
                        }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ca5db35..6f20d5c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -331,6 +331,7 @@ TESTS = \
        dbus/enum-string-marshalling.vala \
        dbus/signals.test \
        dbus/filedescriptor.test \
+       dbus/filedescriptor-async.test \
        dbus/filedescriptor-errors.test \
        dbus/dicts.test \
        dbus/bug596862.vala \
diff --git a/tests/dbus/filedescriptor-async.test b/tests/dbus/filedescriptor-async.test
new file mode 100644
index 0000000..96fc976
--- /dev/null
+++ b/tests/dbus/filedescriptor-async.test
@@ -0,0 +1,99 @@
+Packages: gio-2.0 gio-unix-2.0 posix
+D-Bus
+
+Program: client
+
+[DBus (name = "org.example.Test")]
+interface Test : Object {
+       public abstract async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws 
IOError;
+}
+
+MainLoop main_loop;
+
+async void run () {
+       // client
+       Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
+
+       uint8[] buffer = new uint8[1];
+
+       int[] pipe1 = new int[2];
+       assert (Posix.pipe (pipe1) == 0);
+       buffer[0] = 42;
+       assert (Posix.write (pipe1[1], buffer, 1) == 1);
+       Posix.close (pipe1[1]);
+
+       UnixInputStream j, k;
+       k = yield test.test_in (new UnixInputStream (pipe1[0], true), out j);
+
+       assert (j.read (buffer) == 1);
+       assert (buffer[0] == 23);
+
+       assert (k.read (buffer) == 1);
+       assert (buffer[0] == 11);
+
+       main_loop.quit ();
+}
+
+void main () {
+       // client
+       run.begin ();
+
+       main_loop = new MainLoop (null, false);
+       main_loop.run ();
+}
+
+Program: server
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+       public async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError {
+               uint8[] buffer = new uint8[1];
+
+               assert (i.read (buffer) == 1);
+               assert (buffer[0] == 42);
+
+               int[] pipe1 = new int[2];
+               assert (Posix.pipe (pipe1) == 0);
+               buffer[0] = 23;
+               assert (Posix.write (pipe1[1], buffer, 1) == 1);
+               Posix.close (pipe1[1]);
+
+               int[] pipe2 = new int[2];
+               assert (Posix.pipe (pipe2) == 0);
+               buffer[0] = 11;
+               assert (Posix.write (pipe2[1], buffer, 1) == 1);
+               Posix.close (pipe2[1]);
+
+               Idle.add (test_in.callback);
+               yield;
+
+               j = new UnixInputStream (pipe1[0], true);
+               return new UnixInputStream (pipe2[0], true);
+       }
+}
+
+MainLoop main_loop;
+
+void client_exit (Pid pid, int status) {
+       // client finished, terminate server
+       assert (status == 0);
+       main_loop.quit ();
+}
+
+void main () {
+       var conn = Bus.get_sync (BusType.SESSION);
+       conn.register_object ("/org/example/test", new Test ());
+
+       // try to register service in session bus
+       var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", 
"org.freedesktop.DBus", "RequestName",
+                                             new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
+       assert ((uint) request_result.get_child_value (0) == 1);
+
+       // server ready, spawn client
+       Pid client_pid;
+       Process.spawn_async (null, { "test", "/dbus/filedescriptor-async/client" }, null, 
SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
+       ChildWatch.add (client_pid, client_exit);
+
+       main_loop = new MainLoop ();
+       main_loop.run ();
+}


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