| 335 | } |
| 336 | |
| 337 | static int read_json_from_rpc(struct plugin *p) |
| 338 | { |
| 339 | char *end; |
| 340 | |
| 341 | /* We rely on the double-\n marker which only terminates JSON top |
| 342 | * levels. Thanks lightningd! */ |
| 343 | while ((end = memmem(membuf_elems(&p->rpc_conn->mb), |
| 344 | membuf_num_elems(&p->rpc_conn->mb), "\n\n", 2)) |
| 345 | == NULL) { |
| 346 | ssize_t r; |
| 347 | |
| 348 | /* Make sure we've room for at least READ_CHUNKSIZE. */ |
| 349 | membuf_prepare_space(&p->rpc_conn->mb, READ_CHUNKSIZE); |
| 350 | r = read(p->rpc_conn->fd, membuf_space(&p->rpc_conn->mb), |
| 351 | membuf_num_space(&p->rpc_conn->mb)); |
| 352 | /* lightningd goes away, we go away. */ |
| 353 | if (r == 0) |
| 354 | exit(0); |
| 355 | if (r < 0) |
| 356 | plugin_err(p, "Reading JSON input: %s", strerror(errno)); |
| 357 | membuf_added(&p->rpc_conn->mb, r); |
| 358 | } |
| 359 | |
| 360 | return end + 2 - membuf_elems(&p->rpc_conn->mb); |
| 361 | } |
| 362 | |
| 363 | /* This closes a JSON response and writes it out. */ |
| 364 | static void finish_and_send_json(int fd, struct json_out *jout) |
no test coverage detected