From fba7b11cbefeed8e447954cbdc4db205a8ad89a0 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Fri, 17 Oct 2025 23:39:34 +0200 Subject: [PATCH] C examples updated to the latest libipc API. --- c/README.md | 27 ++++++++++++++++++++++++--- c/makefile | 6 ++++++ c/pong.c | 3 ++- c/pongd.c | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/c/README.md b/c/README.md index f40418e..2f26766 100644 --- a/c/README.md +++ b/c/README.md @@ -1,4 +1,5 @@ -[LibIPC][libipc] C examples: `pong` and `pongd` (simple service and its client, just echoing received messages). +[LibIPC][libipc] C examples: `pong` and `pongd` (simple service and its +client, just echoing received messages). Implementations are straightforward. ## Build @@ -14,10 +15,30 @@ make STATIC=1 # Build static executables. ## Usage ```sh -./zig-out/bin/pongd # run the service -./zig-out/bin/pong # run the client +./pongd # run the service +./pong # run the client ``` +# Using `pong` and `pongd` as debug tools for libipc + +In case you want to use your own version of libipc, first compile your +libipc with `--release=fast` or `--release=small` optimization flags +(as these options remove some zig-related code in the final binary), +then you can compile these tools as is: + +```sh +make STATIC=1 LDFLAGS=/path/to/your/libipc.a +``` + +Then you can run the applications with valgrind if you want: + +```sh +make USE_VALGRIND=1 run-server +make USE_VALGRIND=1 run-client +``` + +See the makefiles in `../mk/` for additional options. + ## LICENSE ISC diff --git a/c/makefile b/c/makefile index f71c2b6..e62b96d 100644 --- a/c/makefile +++ b/c/makefile @@ -15,6 +15,12 @@ build: $(BINS) $(BINS): $(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS) +run-server: + $(VALGRIND) ./pongd + +run-client: + $(VALGRIND) ./pong + clean: rm $(BINS) 2>/dev/null diff --git a/c/pong.c b/c/pong.c index 578aa0a..6692945 100644 --- a/c/pong.c +++ b/c/pong.c @@ -58,7 +58,8 @@ int main(void) { size_t count = 0; while(should_continue) { size = MAX_MSG_SIZE; - ret = ipc_wait_event (ctx, &event_type, &index, &originfd, message, &size); + int newfd; + ret = ipc_wait_event (ctx, &event_type, &index, &originfd, &newfd, message, &size); if (ret != 0) { return err(ctx, "Error while waiting for an event."); } diff --git a/c/pongd.c b/c/pongd.c index ddb64ba..0171606 100644 --- a/c/pongd.c +++ b/c/pongd.c @@ -56,7 +56,8 @@ int main(int argc, char**argv) { size_t count_timer = 0; while(should_continue) { size = MAX_MSG_SIZE; - ret = ipc_wait_event (ctx, &event_type, &index, &originfd, message, &size); + int newfd; + ret = ipc_wait_event (ctx, &event_type, &index, &originfd, &newfd, message, &size); if (ret != 0) { return err (ctx, "Error while waiting for an event."); }