From 8ea70b51ee7632deb2307b482ce76749b4ffe514 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 14 Jan 2023 01:09:03 +0100 Subject: [PATCH] test-bindings: pong.c --- zig-impl/test-bindings/pong.c | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 zig-impl/test-bindings/pong.c diff --git a/zig-impl/test-bindings/pong.c b/zig-impl/test-bindings/pong.c new file mode 100644 index 0000000..3cf60ef --- /dev/null +++ b/zig-impl/test-bindings/pong.c @@ -0,0 +1,52 @@ +#include + +int main(void) { + int ret = 0; + + printf ("Init context.\n"); + void *ctx = NULL; + ret = ipc_context_init (&ctx); + + if (ret != 0) { + printf ("Cannot init context.\n"); + return 1; + } + + printf ("Connect to a 'pong' service.\n"); + ret = ipc_connect_service (ctx, &servicefd, "pong"); + + if (ret != 0) { + printf ("Cannot connect to a service.\n"); + return 1; + } + + printf ("Let's send a message.\n", ret); + ret = ipc_write (ctx, servicefd, "hello, plz bounce me"); + + if (ret != 0) { + printf ("Cannot write to the service.\n"); + return 1; + } + + // TODO: loop over ipc_wait + int event_type, index, originfd = 0; + unsigned int size = 0; + char message[10000]; + printf ("Wait for a response.\n", ret); + ret = ipc_wait (&event_type, &index, &originfd, &size, message); + + if (ret != 0) { + printf ("Error while waiting for an event.\n"); + return 1; + } + + if (size == 0) { + printf ("No message returned.\n"); + return 1; + } + + message[size] = '\0'; + printf ("Response: %s.\n", message); + + return 0; +}