Compare commits

...

2 Commits

Author SHA1 Message Date
e4d2076fa2 Send message to a worker 2024-04-04 22:59:10 -04:00
3f8bd314b6 Make a frontend in front of an actor 2024-03-30 17:14:49 -04:00

View File

@@ -3,13 +3,14 @@
#include <string.h>
#include <czmq.h>
#include <zmsg.h>
#include <zactor.h>
#include <guestfs.h>
#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,40 @@ 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 id
char *id = zmsg_popstr(msg);
// null frame
zmsg_pop(msg);
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
if (STREQ(name, c->name)) {
// send request to worker
printf("name equal\n");
zactor_send(worker, &msg);
} else {
printf("name not equal\n");
}
/* zmsg_t *reply = zmsg_recv(frontend); */
}
zactor_destroy(&worker);
return EXIT_SUCCESS;
}