C examples updated to the latest libipc API.

This commit is contained in:
Philippe Pittoli 2025-10-17 23:39:34 +02:00
parent 4ba5aa93f3
commit fba7b11cbe
4 changed files with 34 additions and 5 deletions

View file

@ -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. Implementations are straightforward.
## Build ## Build
@ -14,10 +15,30 @@ make STATIC=1 # Build static executables.
## Usage ## Usage
```sh ```sh
./zig-out/bin/pongd # run the service ./pongd # run the service
./zig-out/bin/pong # run the client ./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 ## LICENSE
ISC ISC

View file

@ -15,6 +15,12 @@ build: $(BINS)
$(BINS): $(BINS):
$(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS) $(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS)
run-server:
$(VALGRIND) ./pongd
run-client:
$(VALGRIND) ./pong
clean: clean:
rm $(BINS) 2>/dev/null rm $(BINS) 2>/dev/null

View file

@ -58,7 +58,8 @@ int main(void) {
size_t count = 0; size_t count = 0;
while(should_continue) { while(should_continue) {
size = MAX_MSG_SIZE; 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) { if (ret != 0) {
return err(ctx, "Error while waiting for an event."); return err(ctx, "Error while waiting for an event.");
} }

View file

@ -56,7 +56,8 @@ int main(int argc, char**argv) {
size_t count_timer = 0; size_t count_timer = 0;
while(should_continue) { while(should_continue) {
size = MAX_MSG_SIZE; 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) { if (ret != 0) {
return err (ctx, "Error while waiting for an event."); return err (ctx, "Error while waiting for an event.");
} }