]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
gdbus: Fix missing declaration of _fd_list for async methods
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 27 Mar 2018 21:59:59 +0000 (23:59 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 28 Mar 2018 06:53:42 +0000 (08:53 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=794566

codegen/valagdbusclientmodule.vala
tests/Makefile.am
tests/dbus/filedescriptor-async.test [new file with mode: 0644]

index 4d9caa1d317b3cc889e4190f34955fd1f06e5445..32a45de2120b21fa6ceda64633bccc7b863164f2 100644 (file)
@@ -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"));
                        }
 
index ca5db3502780da5bd344b153f8abe418ce62e44e..6f20d5cd01847bf4fa4d165ec60923cbcdb39e3e 100644 (file)
@@ -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 (file)
index 0000000..96fc976
--- /dev/null
@@ -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 ();
+}