devtools/gossipwith: allow --max-messages=0 to avoid reading msgs at all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-08-19 16:32:35 +09:30
parent a358b9ab57
commit e40f07803c
1 changed files with 4 additions and 5 deletions

View File

@ -155,7 +155,7 @@ static struct io_plan *handshake_success(struct io_conn *conn,
args++;
}
for (;;) {
while (max_messages != 0 || pollfd[0].fd != -1) {
beint16_t belen;
u8 *msg;
@ -175,17 +175,16 @@ static struct io_plan *handshake_success(struct io_conn *conn,
} else if (pollfd[1].revents & POLLIN) {
msg = sync_crypto_read(NULL, pps);
if (!msg)
break;
err(1, "Reading msg");
belen = cpu_to_be16(tal_bytelen(msg));
if (!write_all(STDOUT_FILENO, &belen, sizeof(belen))
|| !write_all(STDOUT_FILENO, msg, tal_bytelen(msg)))
err(1, "Writing out msg");
tal_free(msg);
if (--max_messages == 0)
exit(0);
--max_messages;
}
}
err(1, "Reading msg");
exit(0);
}
static char *opt_set_secret(const char *arg, struct secret *s)