| 91 | } |
| 92 | |
| 93 | bool daemon_conn_sync_flush(struct daemon_conn *dc) |
| 94 | { |
| 95 | const u8 *msg; |
| 96 | int daemon_fd; |
| 97 | |
| 98 | /* Flush any current packet. */ |
| 99 | if (!io_flush_sync(dc->conn)) |
| 100 | return false; |
| 101 | |
| 102 | /* Make fd blocking for the duration */ |
| 103 | daemon_fd = io_conn_fd(dc->conn); |
| 104 | if (!io_fd_block(daemon_fd, true)) |
| 105 | return false; |
| 106 | |
| 107 | /* Flush existing messages. */ |
| 108 | while ((msg = msg_dequeue(dc->out)) != NULL) { |
| 109 | int fd = msg_extract_fd(dc->out, msg); |
| 110 | if (fd >= 0) { |
| 111 | tal_free(msg); |
| 112 | if (!fdpass_send(daemon_fd, fd)) |
| 113 | break; |
| 114 | } else if (!wire_sync_write(daemon_fd, take(msg))) |
| 115 | break; |
| 116 | } |
| 117 | io_fd_block(daemon_fd, false); |
| 118 | |
| 119 | /* Success if and only if we flushed them all. */ |
| 120 | return msg == NULL; |
| 121 | } |
| 122 | |
| 123 | static struct io_plan *daemon_conn_start(struct io_conn *conn, |
| 124 | struct daemon_conn *dc) |
no test coverage detected