mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
jsonrpc: allow multiple commands at once.
We now keep multiple commands for a json_connection, and an array of json_streams. When a command wants to write something, we allocate a new json_stream at the end of the array. We always output from the first available json_stream; once that command has finished, we free that and move to the next. Once all are done, we wake the reader. This means we won't read a new command if output is still pending, but as most commands don't start writing until they're ready to write everything, we still get command parallelism. In particular, you can now 'waitinvoice' and 'delinvoice' and it will work even though the 'waitinvoice' blocks. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
f9fd802147
commit
e0d14bddb9
@@ -23,7 +23,9 @@ struct json_stream {
|
||||
|
||||
/* Who is io_writing from this buffer now: NULL if nobody is. */
|
||||
struct io_conn *reader;
|
||||
struct io_plan *(*reader_cb)(struct io_conn *conn, void *arg);
|
||||
struct io_plan *(*reader_cb)(struct io_conn *conn,
|
||||
struct json_stream *js,
|
||||
void *arg);
|
||||
void *reader_arg;
|
||||
size_t len_read;
|
||||
|
||||
@@ -263,7 +265,7 @@ static struct io_plan *json_stream_output_write(struct io_conn *conn,
|
||||
/* We're not doing io_write now, unset. */
|
||||
js->reader = NULL;
|
||||
if (!json_stream_still_writing(js))
|
||||
return js->reader_cb(conn, js->reader_arg);
|
||||
return js->reader_cb(conn, js, js->reader_arg);
|
||||
return io_out_wait(conn, js, json_stream_output_write, js);
|
||||
}
|
||||
|
||||
@@ -276,6 +278,7 @@ static struct io_plan *json_stream_output_write(struct io_conn *conn,
|
||||
struct io_plan *json_stream_output_(struct json_stream *js,
|
||||
struct io_conn *conn,
|
||||
struct io_plan *(*cb)(struct io_conn *conn,
|
||||
struct json_stream *js,
|
||||
void *arg),
|
||||
void *arg)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user