Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
#include <ccan/io/io_plan.h>
#include <errno.h>
#include <ccan/io/io_plan.h>
#include <errno.h>
+static void destroy_conn_close_send_fd(struct io_conn *conn,
+ struct io_plan_arg *arg)
+{
+ close(arg->u1.s);
+}
+
static int do_fd_send(int fd, struct io_plan_arg *arg)
{
if (!fdpass_send(fd, arg->u1.s)) {
static int do_fd_send(int fd, struct io_plan_arg *arg)
{
if (!fdpass_send(fd, arg->u1.s)) {
+ if (arg->u2.vp) {
+ struct io_conn *conn = arg->u2.vp;
+ tal_del_destructor2(conn, destroy_conn_close_send_fd, arg);
+ }
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
arg->u1.s = fd;
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
arg->u1.s = fd;
+ /* We need conn ptr for destructor */
+ arg->u2.vp = fdclose ? conn : NULL;
+ /* If conn closes before sending, we still need to close fd */
+ if (fdclose)
+ tal_add_destructor2(conn, destroy_conn_close_send_fd, arg);
return io_set_plan(conn, IO_OUT, do_fd_send, next, next_arg);
}
return io_set_plan(conn, IO_OUT, do_fd_send, next, next_arg);
}