This queues other traffic from the fd until we get reply. */
| 927 | |
| 928 | /* This queues other traffic from the fd until we get reply. */ |
| 929 | static u8 *master_wait_sync_reply(const tal_t *ctx, |
| 930 | struct peer *peer, |
| 931 | const u8 *msg, |
| 932 | int replytype) |
| 933 | { |
| 934 | u8 *reply; |
| 935 | |
| 936 | status_debug("Sending master %u", fromwire_peektype(msg)); |
| 937 | |
| 938 | if (!wire_sync_write(MASTER_FD, msg)) |
| 939 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 940 | "Could not set sync write to master: %s", |
| 941 | strerror(errno)); |
| 942 | |
| 943 | status_debug("... , awaiting %u", replytype); |
| 944 | |
| 945 | for (;;) { |
| 946 | int type; |
| 947 | |
| 948 | reply = wire_sync_read(ctx, MASTER_FD); |
| 949 | if (!reply) |
| 950 | status_failed(STATUS_FAIL_MASTER_IO, |
| 951 | "Could not set sync read from master: %s", |
| 952 | strerror(errno)); |
| 953 | type = fromwire_peektype(reply); |
| 954 | if (type == replytype) { |
| 955 | status_debug("Got it!"); |
| 956 | break; |
| 957 | } |
| 958 | |
| 959 | status_debug("Nope, got %u instead", type); |
| 960 | msg_enqueue(peer->from_master, take(reply)); |
| 961 | } |
| 962 | |
| 963 | return reply; |
| 964 | } |
| 965 | |
| 966 | static struct hsm_htlc *collect_htlcs(const tal_t *ctx, |
| 967 | const struct htlc **htlc_map) |
no test coverage detected