Make a frontend in front of an actor
This commit is contained in:
@@ -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,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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user