Remove router loop
This commit is contained in:
@@ -134,54 +134,17 @@ int main(int argc, char **argv) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int worker_count = argc - 1;
|
char *path = strtok(argv[1], ":");
|
||||||
|
char *name = strtok(NULL, ":");
|
||||||
// One worker per disk image.
|
printf("name: '%s'\n", name);
|
||||||
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 *ep = endpoint();
|
char *ep = endpoint();
|
||||||
printf("ep: %s\n", ep);
|
printf("ep: %s\n", ep);
|
||||||
zsock_t *frontend = zsock_new_router(ep);
|
zsock_t *worker = zsock_new_rep(ep);
|
||||||
free(ep);
|
free(ep);
|
||||||
|
|
||||||
while (true) {
|
worker_task(worker, path);
|
||||||
zmsg_t *msg = zmsg_recv(frontend);
|
|
||||||
printf("Received a message in the router\n");
|
|
||||||
if (!msg) break;
|
|
||||||
|
|
||||||
// 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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user