From 710d42d071a10093077d30d6e521f9599a9bc997 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 2 Mar 2014 16:35:10 +1030 Subject: [PATCH] io: call finish function after fd is actually closed. This turns out to be the right sequence for pettycoin, which wants to reap the child in the finish routine. From that sample size of 1, this is clearly the Right Thing! Signed-off-by: Rusty Russell --- ccan/io/io.h | 3 ++- ccan/io/poll.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ccan/io/io.h b/ccan/io/io.h index bcdb11fd..ecbeb0b0 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -39,7 +39,8 @@ struct io_conn *io_new_conn_(int fd, struct io_plan plan); * * @finish will be called when an I/O operation fails, or you call * io_close() on the connection. errno will be set to the value - * after the failed I/O, or at the call to io_close(). + * after the failed I/O, or at the call to io_close(). The fd + * will be closed (unless a duplex) before @finish is called. * * Example: * static void finish(struct io_conn *conn, void *unused) diff --git a/ccan/io/poll.c b/ccan/io/poll.c index d7b9eb56..e3f595c9 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -188,11 +188,6 @@ bool add_duplex(struct io_conn *c) void backend_del_conn(struct io_conn *conn) { - if (conn->finish) { - /* Saved by io_close */ - errno = conn->plan.u1.s; - conn->finish(conn, conn->finish_arg); - } if (timeout_active(conn)) backend_del_timeout(conn); io_alloc.free(conn->timeout); @@ -205,6 +200,11 @@ void backend_del_conn(struct io_conn *conn) } else del_fd(&conn->fd); num_closing--; + if (conn->finish) { + /* Saved by io_close */ + errno = conn->plan.u1.s; + conn->finish(conn, conn->finish_arg); + } free_conn(conn); } -- 2.39.2