| 1137 | struct json_connection *jcon); |
| 1138 | |
| 1139 | static struct io_plan *start_json_stream(struct io_conn *conn, |
| 1140 | struct json_connection *jcon) |
| 1141 | { |
| 1142 | struct json_stream *js; |
| 1143 | |
| 1144 | /* If something has created an output buffer, start streaming. */ |
| 1145 | js = list_top(&jcon->jsouts, struct json_stream, list); |
| 1146 | if (js) { |
| 1147 | size_t len; |
| 1148 | const char *p = json_out_contents(js->jout, &len); |
| 1149 | if (len) |
| 1150 | log_io(jcon->log, LOG_IO_OUT, NULL, "", p, len); |
| 1151 | return json_stream_output(js, conn, |
| 1152 | stream_out_complete, jcon); |
| 1153 | } |
| 1154 | |
| 1155 | /* Tell reader it can run next command. */ |
| 1156 | io_wake(conn); |
| 1157 | |
| 1158 | /* Once the stop_conn conn is drained, we can shut down. */ |
| 1159 | if (jcon->ld->stop_conn == conn |
| 1160 | && (jcon->ld->state == LD_STATE_RUNNING || jcon->ld->state == LD_STATE_GRACE)) { |
| 1161 | /* Return us to toplevel lightningd.c */ |
| 1162 | log_debug(jcon->ld->log, "io_break: %s", __func__); |
| 1163 | io_break(jcon->ld); |
| 1164 | /* We never come back. */ |
| 1165 | return io_out_wait(conn, conn, io_never, conn); |
| 1166 | } |
| 1167 | |
| 1168 | return io_out_wait(conn, jcon, start_json_stream, jcon); |
| 1169 | } |
| 1170 | |
| 1171 | /* Command has completed writing, and we've written it all out to conn. */ |
| 1172 | static struct io_plan *stream_out_complete(struct io_conn *conn, |
no test coverage detected