From: Rusty Russell Date: Mon, 14 Oct 2013 10:58:35 +0000 (+1030) Subject: ccan/io: put explicit poll flags in the plan. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=7f4e5627dd9797b3f5eb4854bdca122c2679c451 ccan/io: put explicit poll flags in the plan. Weaning off enum io_state, to allow custom ones. Signed-off-by: Rusty Russell --- diff --git a/ccan/io/backend.h b/ccan/io/backend.h index 3c5b3f8b..2eb33309 100644 --- a/ccan/io/backend.h +++ b/ccan/io/backend.h @@ -77,6 +77,7 @@ struct io_conn { struct io_conn *duplex; struct io_timeout *timeout; + int pollflag; /* 0, POLLIN or POLLOUT */ enum io_state state; union { struct io_state_read read; diff --git a/ccan/io/io.c b/ccan/io/io.c index ec4d4fab..2ce5d6ae 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -8,6 +8,7 @@ #include #include #include +#include void *io_loop_return; @@ -56,6 +57,7 @@ struct io_conn *io_new_conn_(int fd, conn->fd.next = start; conn->fd.finish = finish; conn->fd.finish_arg = conn->fd.next_arg = arg; + conn->pollflag = 0; conn->state = NEXT; conn->duplex = NULL; conn->timeout = NULL; @@ -84,6 +86,7 @@ struct io_conn *io_duplex_(struct io_conn *old, conn->fd.next = start; conn->fd.finish = finish; conn->fd.finish_arg = conn->fd.next_arg = arg; + conn->pollflag = 0; conn->state = NEXT; conn->duplex = old; conn->timeout = NULL; @@ -125,6 +128,7 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len, conn->u.write.len = len; conn->fd.next = cb; conn->fd.next_arg = arg; + conn->pollflag = POLLOUT; return to_ioplan(WRITE); } @@ -137,6 +141,7 @@ struct io_plan *io_read_(struct io_conn *conn, void *data, size_t len, conn->u.read.len = len; conn->fd.next = cb; conn->fd.next_arg = arg; + conn->pollflag = POLLIN; return to_ioplan(READ); } @@ -149,6 +154,7 @@ struct io_plan *io_read_partial_(struct io_conn *conn, void *data, size_t *len, conn->u.readpart.lenp = len; conn->fd.next = cb; conn->fd.next_arg = arg; + conn->pollflag = POLLIN; return to_ioplan(READPART); } @@ -162,11 +168,13 @@ struct io_plan *io_write_partial_(struct io_conn *conn, conn->u.writepart.lenp = len; conn->fd.next = cb; conn->fd.next_arg = arg; + conn->pollflag = POLLOUT; return to_ioplan(WRITEPART); } struct io_plan *io_idle(struct io_conn *conn) { + conn->pollflag = 0; return to_ioplan(IDLE); } diff --git a/ccan/io/poll.c b/ccan/io/poll.c index 9cef3ce3..bd76ebc2 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -112,20 +112,6 @@ void del_listener(struct io_listener *l) del_fd(&l->fd); } -static int pollmask(enum io_state state) -{ - switch (state) { - case READ: - case READPART: - return POLLIN; - case WRITE: - case WRITEPART: - return POLLOUT; - default: - return 0; - } -} - void backend_set_state(struct io_conn *conn, struct io_plan *plan) { enum io_state state = from_ioplan(plan); @@ -134,9 +120,9 @@ void backend_set_state(struct io_conn *conn, struct io_plan *plan) if (pfd->events) num_waiting--; - pfd->events = pollmask(state); + pfd->events = conn->pollflag; if (conn->duplex) { - int mask = pollmask(conn->duplex->state); + int mask = conn->duplex->pollflag; /* You can't *both* read/write. */ assert(!mask || pfd->events != mask); pfd->events |= mask; @@ -282,7 +268,7 @@ void *io_loop(void) } else if (events & (POLLIN|POLLOUT)) { r--; if (c->duplex) { - int mask = pollmask(c->duplex->state); + int mask = c->duplex->pollflag; if (events & mask) { ready(c->duplex); events &= ~mask;