MCPcopy Create free account
hub / github.com/ElementsProject/lightning / read_json_from_rpc

Function read_json_from_rpc

plugins/libplugin.c:337–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337static 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. */
364static void finish_and_send_json(int fd, struct json_out *jout)

Callers 1

read_rpc_replyFunction · 0.85

Calls 2

memmemFunction · 0.85
plugin_errFunction · 0.70

Tested by

no test coverage detected