Browse Source

common/daemon_conn: remove finished function.

For the moment, caller sets it manually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
plugin-1
Rusty Russell 6 years ago
parent
commit
689d51cba5
  1. 10
      common/daemon_conn.c
  2. 4
      common/daemon_conn.h
  3. 7
      connectd/connectd.c
  4. 21
      gossipd/gossipd.c
  5. 2
      hsmd/hsmd.c

10
common/daemon_conn.c

@ -69,27 +69,21 @@ bool daemon_conn_sync_flush(struct daemon_conn *dc)
static struct io_plan *daemon_conn_start(struct io_conn *conn,
struct daemon_conn *dc)
{
dc->conn = conn;
return io_duplex(conn, daemon_conn_read_next(conn, dc),
daemon_conn_write_next(conn, dc));
}
void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
struct io_plan *(*daemon_conn_recv)(struct io_conn *,
struct daemon_conn *),
void (*finish)(struct io_conn *, struct daemon_conn *dc))
struct daemon_conn *))
{
struct io_conn *conn;
dc->daemon_conn_recv = daemon_conn_recv;
dc->ctx = ctx;
dc->msg_in = NULL;
msg_queue_init(&dc->out, dc->ctx);
dc->msg_queue_cleared_cb = NULL;
conn = io_new_conn(ctx, fd, daemon_conn_start, dc);
if (finish)
io_set_finish(conn, finish, dc);
dc->conn = io_new_conn(ctx, fd, daemon_conn_start, dc);
}
void daemon_conn_clear(struct daemon_conn *dc)

4
common/daemon_conn.h

@ -36,12 +36,10 @@ struct daemon_conn {
* @dc: daemon_conn to initialize
* @fd: socket file descriptor to wrap
* @daemon_conn_recv: callback function to be called upon receiving a message
* @finish: finish function if connection is closed (can be NULL)
*/
void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
struct io_plan *(*daemon_conn_recv)(
struct io_conn *, struct daemon_conn *),
void (*finish)(struct io_conn *, struct daemon_conn *));
struct io_conn *, struct daemon_conn *));
/**
* daemon_conn_clear - discard a daemon conn without triggering finish.

7
connectd/connectd.c

@ -1424,7 +1424,8 @@ bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
*
* The C++ method of omitting unused parameter names is *much* neater, and I
* hope we'll eventually see it in a C standard. */
static void master_gone(struct io_conn *unused UNUSED, struct daemon_conn *dc UNUSED)
static void master_gone(struct io_conn *unused UNUSED,
struct daemon *daemon UNUSED)
{
/* Can't tell master, it's gone. */
exit(2);
@ -1445,8 +1446,8 @@ int main(int argc, char *argv[])
list_head_init(&daemon->connecting);
daemon->listen_fds = tal_arr(daemon, struct listen_fd, 0);
/* stdin == control */
daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req,
master_gone);
daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req);
io_set_finish(daemon->master.conn, master_gone, daemon);
/* This tells the status_* subsystem to use this connection to send
* our status_ and failed messages. */

21
gossipd/gossipd.c

@ -1227,13 +1227,6 @@ static struct io_plan *owner_msg_in(struct io_conn *conn,
return daemon_conn_read_next(conn, dc);
}
static void free_peer(struct io_conn *conn, struct daemon_conn *dc)
{
struct peer *peer = dc->ctx;
tal_free(peer);
}
static struct io_plan *connectd_new_peer(struct io_conn *conn,
struct daemon *daemon,
const u8 *msg)
@ -1262,7 +1255,9 @@ static struct io_plan *connectd_new_peer(struct io_conn *conn,
peer->daemon = daemon;
peer->remote = tal(peer, struct daemon_conn);
daemon_conn_init(peer, peer->remote, fds[0], owner_msg_in, free_peer);
daemon_conn_init(peer, peer->remote, fds[0], owner_msg_in);
/* Free peer if conn closed. */
tal_steal(peer->remote->conn, peer);
peer->remote->msg_queue_cleared_cb = nonlocal_dump_gossip;
peer->scid_queries = NULL;
@ -2140,7 +2135,7 @@ static struct io_plan *connectd_req(struct io_conn *conn,
}
#ifndef TESTING
static void master_gone(struct io_conn *unused UNUSED, struct daemon_conn *dc UNUSED)
static void master_gone(struct io_conn *unused UNUSED, struct daemon *daemon UNUSED)
{
/* Can't tell master, it's gone. */
exit(2);
@ -2159,11 +2154,11 @@ int main(int argc, char *argv[])
timers_init(&daemon->timers, time_mono());
/* stdin == control */
daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req,
master_gone);
daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req);
io_set_finish(daemon->master.conn, master_gone, daemon);
status_setup_async(&daemon->master);
daemon_conn_init(daemon, &daemon->connectd, CONNECTD_FD, connectd_req,
NULL);
daemon_conn_init(daemon, &daemon->connectd, CONNECTD_FD, connectd_req);
for (;;) {
struct timer *expired = NULL;

2
hsmd/hsmd.c

@ -1728,7 +1728,7 @@ int main(int argc, char *argv[])
/* A trivial daemon_conn just for writing. */
status_conn = tal(NULL, struct daemon_conn);
daemon_conn_init(status_conn, status_conn, STDIN_FILENO,
(void *)io_never, NULL);
(void *)io_never);
status_setup_async(status_conn);
uintmap_init(&clients);

Loading…
Cancel
Save