From 174fe59fdce127808420986f56987205ecab2858 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 14 Oct 2013 21:28:35 +1030 Subject: [PATCH] ccan/io: remove next & finish from union. Sure, both listener and conn need them, but for different things (listener uses them simply to set up conn). Putting them in the common union was a mistake. Signed-off-by: Rusty Russell --- ccan/io/backend.h | 17 +++++++++++------ ccan/io/io.c | 44 ++++++++++++++++++++++---------------------- ccan/io/poll.c | 10 ++++------ 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/ccan/io/backend.h b/ccan/io/backend.h index 2eb33309..bc88c289 100644 --- a/ccan/io/backend.h +++ b/ccan/io/backend.h @@ -8,18 +8,17 @@ struct fd { int fd; bool listener; size_t backend_info; - - struct io_plan *(*next)(struct io_conn *, void *arg); - void *next_arg; - - void (*finish)(struct io_conn *, void *arg); - void *finish_arg; }; /* Listeners create connections. */ struct io_listener { struct fd fd; + + /* These are for connections we create. */ + struct io_plan *(*next)(struct io_conn *, void *arg); + void (*finish)(struct io_conn *, void *arg); + void *conn_arg; }; enum io_state { @@ -74,6 +73,12 @@ struct io_timeout { struct io_conn { struct fd fd; + struct io_plan *(*next)(struct io_conn *, void *arg); + void *next_arg; + + void (*finish)(struct io_conn *, void *arg); + void *finish_arg; + struct io_conn *duplex; struct io_timeout *timeout; diff --git a/ccan/io/io.c b/ccan/io/io.c index 2ce5d6ae..150f7269 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -25,9 +25,9 @@ struct io_listener *io_new_listener_(int fd, l->fd.listener = true; l->fd.fd = fd; - l->fd.next = start; - l->fd.finish = finish; - l->fd.finish_arg = l->fd.next_arg = arg; + l->next = start; + l->finish = finish; + l->conn_arg = arg; if (!add_listener(l)) { free(l); return NULL; @@ -54,9 +54,9 @@ struct io_conn *io_new_conn_(int fd, conn->fd.listener = false; conn->fd.fd = fd; - conn->fd.next = start; - conn->fd.finish = finish; - conn->fd.finish_arg = conn->fd.next_arg = arg; + conn->next = start; + conn->finish = finish; + conn->finish_arg = conn->next_arg = arg; conn->pollflag = 0; conn->state = NEXT; conn->duplex = NULL; @@ -83,9 +83,9 @@ struct io_conn *io_duplex_(struct io_conn *old, conn->fd.listener = false; conn->fd.fd = old->fd.fd; - conn->fd.next = start; - conn->fd.finish = finish; - conn->fd.finish_arg = conn->fd.next_arg = arg; + conn->next = start; + conn->finish = finish; + conn->finish_arg = conn->next_arg = arg; conn->pollflag = 0; conn->state = NEXT; conn->duplex = old; @@ -126,8 +126,8 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len, { conn->u.write.buf = data; conn->u.write.len = len; - conn->fd.next = cb; - conn->fd.next_arg = arg; + conn->next = cb; + conn->next_arg = arg; conn->pollflag = POLLOUT; return to_ioplan(WRITE); } @@ -139,8 +139,8 @@ struct io_plan *io_read_(struct io_conn *conn, void *data, size_t len, { conn->u.read.buf = data; conn->u.read.len = len; - conn->fd.next = cb; - conn->fd.next_arg = arg; + conn->next = cb; + conn->next_arg = arg; conn->pollflag = POLLIN; return to_ioplan(READ); } @@ -152,8 +152,8 @@ struct io_plan *io_read_partial_(struct io_conn *conn, void *data, size_t *len, { conn->u.readpart.buf = data; conn->u.readpart.lenp = len; - conn->fd.next = cb; - conn->fd.next_arg = arg; + conn->next = cb; + conn->next_arg = arg; conn->pollflag = POLLIN; return to_ioplan(READPART); } @@ -166,8 +166,8 @@ struct io_plan *io_write_partial_(struct io_conn *conn, { conn->u.writepart.buf = data; conn->u.writepart.lenp = len; - conn->fd.next = cb; - conn->fd.next_arg = arg; + conn->next = cb; + conn->next_arg = arg; conn->pollflag = POLLOUT; return to_ioplan(WRITEPART); } @@ -186,8 +186,8 @@ void io_wake_(struct io_conn *conn, if (conn->state == FINISHED) return; assert(conn->state == IDLE); - conn->fd.next = fn; - conn->fd.next_arg = arg; + conn->next = fn; + conn->next_arg = arg; backend_set_state(conn, to_ioplan(NEXT)); } @@ -195,7 +195,7 @@ static struct io_plan *do_next(struct io_conn *conn) { if (timeout_active(conn)) backend_del_timeout(conn); - return conn->fd.next(conn, conn->fd.next_arg); + return conn->next(conn, conn->next_arg); } struct io_plan *do_ready(struct io_conn *conn) @@ -259,8 +259,8 @@ struct io_plan *io_break_(struct io_conn *conn, void *ret, void *arg) { io_loop_return = ret; - conn->fd.next = fn; - conn->fd.next_arg = arg; + conn->next = fn; + conn->next_arg = arg; return to_ioplan(NEXT); } diff --git a/ccan/io/poll.c b/ccan/io/poll.c index bd76ebc2..5982ef15 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -90,8 +90,8 @@ bool add_duplex(struct io_conn *c) static void del_conn(struct io_conn *conn) { - if (conn->fd.finish) - conn->fd.finish(conn, conn->fd.finish_arg); + if (conn->finish) + conn->finish(conn, conn->finish_arg); if (timeout_active(conn)) backend_del_timeout(conn); free(conn->timeout); @@ -146,7 +146,7 @@ static void accept_conn(struct io_listener *l) /* FIXME: What to do here? */ if (fd < 0) return; - c = io_new_conn(fd, l->fd.next, l->fd.finish, l->fd.next_arg); + c = io_new_conn(fd, l->next, l->finish, l->conn_arg); if (!c) { close(fd); return; @@ -174,9 +174,7 @@ static void finish_and_next(bool finished_only) free(c); i--; } else if (!finished_only && c->state == NEXT) { - backend_set_state(c, - c->fd.next(c, - c->fd.next_arg)); + backend_set_state(c, c->next(c, c->next_arg)); num_next--; } } -- 2.39.2