1 Packages: gio-2.0 gio-unix-2.0 posix
6 [DBus (name = "org.example.Test")]
7 interface Test : Object {
8 public abstract async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError;
15 Test test = yield Bus.get_proxy (BusType.SESSION, "org.example.Test", "/org/example/test");
17 uint8[] buffer = new uint8[1];
19 int[] pipe1 = new int[2];
20 assert (Posix.pipe (pipe1) == 0);
22 assert (Posix.write (pipe1[1], buffer, 1) == 1);
23 Posix.close (pipe1[1]);
26 k = yield test.test_in (new UnixInputStream (pipe1[0], true), out j);
28 assert (j.read (buffer) == 1);
29 assert (buffer[0] == 23);
31 assert (k.read (buffer) == 1);
32 assert (buffer[0] == 11);
41 main_loop = new MainLoop (null, false);
47 [DBus (name = "org.example.Test")]
49 public async UnixInputStream test_in (UnixInputStream i, out UnixInputStream j) throws IOError {
50 uint8[] buffer = new uint8[1];
52 assert (i.read (buffer) == 1);
53 assert (buffer[0] == 42);
55 int[] pipe1 = new int[2];
56 assert (Posix.pipe (pipe1) == 0);
58 assert (Posix.write (pipe1[1], buffer, 1) == 1);
59 Posix.close (pipe1[1]);
61 int[] pipe2 = new int[2];
62 assert (Posix.pipe (pipe2) == 0);
64 assert (Posix.write (pipe2[1], buffer, 1) == 1);
65 Posix.close (pipe2[1]);
67 Idle.add (test_in.callback);
70 j = new UnixInputStream (pipe1[0], true);
71 return new UnixInputStream (pipe2[0], true);
77 void client_exit (Pid pid, int status) {
78 // client finished, terminate server
84 var conn = Bus.get_sync (BusType.SESSION);
85 conn.register_object ("/org/example/test", new Test ());
87 // try to register service in session bus
88 var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
89 new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
90 assert ((uint) request_result.get_child_value (0) == 1);
92 // server ready, spawn client
94 Process.spawn_async (null, { "test", "/dbus/filedescriptor-async/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD, null, out client_pid);
95 ChildWatch.add (client_pid, client_exit);
97 main_loop = new MainLoop ();