From 3f8bd314b67497b694b465158638ab0890688cc6 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sat, 30 Mar 2024 16:18:47 -0400 Subject: [PATCH] Make a frontend in front of an actor --- guestfs-inspectd.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index 601bbc2..4b3f3e7 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -3,13 +3,14 @@ #include #include #include +#include #include #include "libguestfs-inspect.h" #define STREQ(a, b) (strcmp((a), (b)) == 0) -static void *worker_task(zsock_t*, char*); +static void worker_task(zsock_t*, char*); static int compare_key_len(const void*, const void*); static int count_mountpoints(char *const *argv); @@ -88,7 +89,7 @@ static guestfs_h* init_guestfs(char *disk_path) { return g; } -static void *worker_task(zsock_t *pipe, char *disk_path) { +static void worker_task(zsock_t *pipe, char *disk_path) { guestfs_h *g; g = init_guestfs(disk_path); @@ -150,16 +151,35 @@ int main(int argc, char **argv) { char *path = strtok(argv[1], ":"); char *name = strtok(NULL, ":"); printf("name: '%s'\n", name); + zactor_t *worker = zactor_new(worker_task, path); char *ep = guestfs_inspect_endpoint(); printf("ep: %s\n", ep); - zsock_t *worker = zsock_new_rep(ep); + + zsock_t *frontend = zsock_new(ZMQ_ROUTER); + zsock_bind(frontend, ep); free(ep); - worker_task(worker, path); - zsock_destroy(&worker); + while (true) { + zmsg_t *msg = zmsg_recv(frontend); + if (!msg) { + break; + } - zsock_destroy(&worker); + // reply addr + zmsg_pop(msg); + // null frame + zmsg_pop(msg); + struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg); + + if (STREQ(name, c->name)) { + printf("name equal\n"); + } else { + printf("name not equal\n"); + } + } + + zactor_destroy(&worker); return EXIT_SUCCESS; }