]> git.ozlabs.org Git - ccan/commitdiff
ccan/io: put explicit poll flags in the plan.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 14 Oct 2013 10:58:35 +0000 (21:28 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 14 Oct 2013 10:58:35 +0000 (21:28 +1030)
Weaning off enum io_state, to allow custom ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io/backend.h
ccan/io/io.c
ccan/io/poll.c

index 3c5b3f8b781bb38ab014fee995b9272ad4164c28..2eb333091c187b4c39dc5ade4e4e7d84ee6054c2 100644 (file)
@@ -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;
index ec4d4fabbc19df27e67059c652787df4e37f99eb..2ce5d6ae3224b1ac8cd5c51b5e354871a46f8e2c 100644 (file)
@@ -8,6 +8,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <poll.h>
 
 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);
 }
 
index 9cef3ce36ee5894523cd82f41937390e1f4e9d0b..bd76ebc2aa5701011f1844c9ac54bd49f991b944 100644 (file)
@@ -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;