Remove router loop

This commit is contained in:
2024-03-03 15:22:36 -05:00
parent ea58a6ebd3
commit 83f62dc217

View File

@@ -134,54 +134,17 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
const int worker_count = argc - 1;
// One worker per disk image.
struct {
char *name;
zactor_t *worker;
} worker_map[worker_count];
for (int i = 0; i < worker_count; i++) {
char *path = strtok(argv[i+1], ":");
worker_map[i].name = strtok(NULL, ":");
printf("name: %s\n", worker_map[i].name);
worker_map[i].worker = zactor_new(worker_task, path);
}
char *path = strtok(argv[1], ":");
char *name = strtok(NULL, ":");
printf("name: '%s'\n", name);
char *ep = endpoint();
printf("ep: %s\n", ep);
zsock_t *frontend = zsock_new_router(ep);
zsock_t *worker = zsock_new_rep(ep);
free(ep);
while (true) {
zmsg_t *msg = zmsg_recv(frontend);
printf("Received a message in the router\n");
if (!msg) break;
worker_task(worker, path);
// Find the worker with the given name.
zactor_t *worker = NULL;
struct guestfs_inpsect_command *cmd = (struct guestfs_inpsect_command *) zmsg_last(msg);
for (int i = 0; i < worker_count; i++) {
if (STREQ(cmd->name, worker_map[i].name)) {
worker = worker_map[i].name;
break;
}
}
// TODO: REMOVE
if (!worker) {
worker = worker_map[0].worker;
}
// TODO: REMOVE
if (worker) {
zmsg_send(&msg, zactor_sock(worker));
} else {
// The name specified does not exist.
printf("There is no drive with the name %s\n.", cmd->name);
}
}
return EXIT_SUCCESS;
}