| 965 | struct json_connection *jcon); |
| 966 | |
| 967 | static struct io_plan *start_json_stream(struct io_conn *conn, |
| 968 | struct json_connection *jcon) |
| 969 | { |
| 970 | /* If something has created an output buffer, start streaming. */ |
| 971 | if (tal_count(jcon->js_arr)) { |
| 972 | size_t len; |
| 973 | const char *p = json_out_contents(jcon->js_arr[0]->jout, &len); |
| 974 | if (len) |
| 975 | log_io(jcon->log, LOG_IO_OUT, NULL, "", p, len); |
| 976 | return json_stream_output(jcon->js_arr[0], conn, |
| 977 | stream_out_complete, jcon); |
| 978 | } |
| 979 | |
| 980 | /* Tell reader it can run next command. */ |
| 981 | io_wake(conn); |
| 982 | |
| 983 | /* Once the stop_conn conn is drained, we can shut down. */ |
| 984 | if (jcon->ld->stop_conn == conn && jcon->ld->state == LD_STATE_RUNNING) { |
| 985 | /* Return us to toplevel lightningd.c */ |
| 986 | log_debug(jcon->ld->log, "io_break: %s", __func__); |
| 987 | io_break(jcon->ld); |
| 988 | /* We never come back. */ |
| 989 | return io_out_wait(conn, conn, io_never, conn); |
| 990 | } |
| 991 | |
| 992 | return io_out_wait(conn, jcon, start_json_stream, jcon); |
| 993 | } |
| 994 | |
| 995 | /* Command has completed writing, and we've written it all out to conn. */ |
| 996 | static struct io_plan *stream_out_complete(struct io_conn *conn, |
no test coverage detected