commit 8bd27e0aeb68e503135cdf6b2dc5a88ffc94ecd1
parent d6d69b283683bea8b5359731d7f1cb6068322d66
Author: William Casarin <jb55@jb55.com>
Date: Sat, 22 Jan 2022 12:51:57 -0800
rpc/commando: handle larger responses
Diffstat:
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/commando.c b/commando.c
@@ -2,10 +2,7 @@
#include "lnsocket.h"
#include "cursor.h"
#include "endian.h"
-
-#define COMMANDO_CMD 0x4c4f
-#define COMMANDO_REPLY_CONTINUES 0x594b
-#define COMMANDO_REPLY_TERM 0x594d
+#include "commando.h"
int commando_make_rpc_msg(const char *method, const char *params,
const char *rune, uint64_t req_id, unsigned char *buf,
diff --git a/commando.h b/commando.h
@@ -4,6 +4,10 @@
#include <inttypes.h>
+#define COMMANDO_CMD 0x4c4f
+#define COMMANDO_REPLY_CONTINUES 0x594b
+#define COMMANDO_REPLY_TERM 0x594d
+
int commando_make_rpc_msg(const char *method, const char *params, const char *rune, uint64_t req_id, unsigned char *buf, int buflen, unsigned short *outlen);
#endif /* LNSOCKET_COMMANDO */
diff --git a/error.c b/error.c
@@ -41,9 +41,9 @@ void print_error_backtrace(struct errors *errors)
while (errs.p < errors->cur.p) {
if (!cursor_pull_error(&errs, &err)) {
- printf("backtrace: couldn't pull error\n");
+ fprintf(stderr, "backtrace: couldn't pull error\n");
return;
}
- printf("%s\n", err.msg);
+ fprintf(stderr, "%s\n", err.msg);
}
}
diff --git a/rpc.c b/rpc.c
@@ -57,10 +57,26 @@ int main(int argc, const char *argv[])
if (verbose)
fprintf(stderr, "waiting for response...\n");
- if (!(ok = lnsocket_recv(ln, &msgtype, &buf, &len)))
- goto done;
+ while (1) {
+ if (!(ok = lnsocket_recv(ln, &msgtype, &buf, &len)))
+ goto done;
+
+ printf("%.*s", len - 8, buf + 8);
+
+ switch (msgtype) {
+ case COMMANDO_REPLY_TERM:
+ printf("\n");
+ goto done;
+ case COMMANDO_REPLY_CONTINUES:
+ continue;
+ default:
+ printf("\n");
+ fprintf(stderr, "unknown msgtype %d\n", msgtype);
+ ok = 0;
+ goto done;
+ }
+ }
- printf("%.*s\n", len - 8, buf + 8);
done:
lnsocket_print_errors(ln);
lnsocket_destroy(ln);