daemon_conn: simplify msg_queue_cleared_cb.

Now it just returns true if it queued something.  This allows it
to queue multiple packets, and lets it share code paths with other code
in future patches.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-03-14 02:14:55 +10:30
parent 87effd90c2
commit 5e333b75b9
3 changed files with 16 additions and 18 deletions

View File

@ -16,7 +16,10 @@ struct io_plan *daemon_conn_read_next(struct io_conn *conn,
struct io_plan *daemon_conn_write_next(struct io_conn *conn, struct io_plan *daemon_conn_write_next(struct io_conn *conn,
struct daemon_conn *dc) struct daemon_conn *dc)
{ {
const u8 *msg = msg_dequeue(&dc->out); const u8 *msg;
again:
msg = msg_dequeue(&dc->out);
if (msg) { if (msg) {
int fd = msg_extract_fd(msg); int fd = msg_extract_fd(msg);
if (fd >= 0) if (fd >= 0)
@ -25,11 +28,10 @@ struct io_plan *daemon_conn_write_next(struct io_conn *conn,
return io_write_wire(conn, take(msg), daemon_conn_write_next, return io_write_wire(conn, take(msg), daemon_conn_write_next,
dc); dc);
} else if (dc->msg_queue_cleared_cb) { } else if (dc->msg_queue_cleared_cb) {
return dc->msg_queue_cleared_cb(conn, dc); if (dc->msg_queue_cleared_cb(conn, dc))
} else { goto again;
return msg_queue_wait(conn, &dc->out,
daemon_conn_write_next, dc);
} }
return msg_queue_wait(conn, &dc->out, daemon_conn_write_next, dc);
} }
bool daemon_conn_sync_flush(struct daemon_conn *dc) bool daemon_conn_sync_flush(struct daemon_conn *dc)

View File

@ -24,10 +24,9 @@ struct daemon_conn {
struct io_plan *(*daemon_conn_recv)(struct io_conn *conn, struct io_plan *(*daemon_conn_recv)(struct io_conn *conn,
struct daemon_conn *); struct daemon_conn *);
/* Called whenever we've cleared the msg_out queue. Used to /* Called whenever we've cleared the msg_out queue. If it returns
* inject things into the write loop */ * true, it has added packets to msg_out queue. */
struct io_plan *(*msg_queue_cleared_cb)(struct io_conn *conn, bool (*msg_queue_cleared_cb)(struct io_conn *, struct daemon_conn *);
struct daemon_conn *);
}; };
/** /**

View File

@ -423,8 +423,7 @@ static struct io_plan *init_new_peer(struct io_conn *conn,
static struct io_plan *owner_msg_in(struct io_conn *conn, static struct io_plan *owner_msg_in(struct io_conn *conn,
struct daemon_conn *dc); struct daemon_conn *dc);
static struct io_plan *nonlocal_dump_gossip(struct io_conn *conn, static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc);
struct daemon_conn *dc);
/* Create a node_announcement with the given signature. It may be NULL /* Create a node_announcement with the given signature. It may be NULL
* in the case we need to create a provisional announcement for the * in the case we need to create a provisional announcement for the
@ -914,7 +913,7 @@ static bool send_peer_with_fds(struct peer *peer, const u8 *msg)
* *
* Registered as `msg_queue_cleared_cb` by the `peer->remote`. * Registered as `msg_queue_cleared_cb` by the `peer->remote`.
*/ */
static struct io_plan *nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc) static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc)
{ {
struct queued_message *next; struct queued_message *next;
struct peer *peer = dc->ctx; struct peer *peer = dc->ctx;
@ -925,22 +924,20 @@ static struct io_plan *nonlocal_dump_gossip(struct io_conn *conn, struct daemon_
/* Nothing to do if we're not gossiping */ /* Nothing to do if we're not gossiping */
if (!peer->gossip_sync) if (!peer->gossip_sync)
return msg_queue_wait(conn, &peer->remote->out, return false;
daemon_conn_write_next, dc);
next = next_broadcast_message(peer->daemon->rstate->broadcasts, next = next_broadcast_message(peer->daemon->rstate->broadcasts,
&peer->broadcast_index); &peer->broadcast_index);
if (!next) { if (!next) {
peer->gossip_sync = false; peer->gossip_sync = false;
return msg_queue_wait(conn, &peer->remote->out, return false;
daemon_conn_write_next, dc);
} else { } else {
u8 *msg = towire_gossip_send_gossip(conn, u8 *msg = towire_gossip_send_gossip(conn,
peer->broadcast_index, peer->broadcast_index,
next->payload); next->payload);
return io_write_wire(conn, take(msg), daemon_conn_send(peer->remote, take(msg));
nonlocal_dump_gossip, dc); return true;
} }
} }