Archived
3
0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
libipc-old/zig-impl/test-bindings/pong.c

53 lines
1010 B
C
Raw Normal View History

2023-01-14 01:09:03 +01:00
#include <stdio.h>
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;
}