]> git.ozlabs.org Git - ccan/commitdiff
ccan/io: make enum io_state namespace-safe.
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)
Ready for exposure.

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

index 86db8c3d1de44983e3061bb33699a7783d69c88d..d75b516b763e85ef06278ff07271204b19f6c90d 100644 (file)
@@ -28,11 +28,10 @@ enum io_result {
 };
 
 enum io_state {
-       IO,
-       NEXT, /* eg starting, woken from idle, return from io_break. */
-       IDLE,
-       FINISHED,
-       PROCESSING /* We expect them to change this now. */
+       IO_IO,
+       IO_NEXT, /* eg starting, woken from idle, return from io_break. */
+       IO_IDLE,
+       IO_FINISHED
 };
 
 static inline enum io_state from_ioplan(struct io_plan *op)
index 84be1758330e61481638ce31d72826799089f81b..c725850fd810eeb3e5a14c1ad0e6a64b924a8b6f 100644 (file)
@@ -58,7 +58,7 @@ struct io_conn *io_new_conn_(int fd,
        conn->finish = finish;
        conn->finish_arg = conn->next_arg = arg;
        conn->pollflag = 0;
-       conn->state = NEXT;
+       conn->state = IO_NEXT;
        conn->duplex = NULL;
        conn->timeout = NULL;
        if (!add_conn(conn)) {
@@ -87,7 +87,7 @@ struct io_conn *io_duplex_(struct io_conn *old,
        conn->finish = finish;
        conn->finish_arg = conn->next_arg = arg;
        conn->pollflag = 0;
-       conn->state = NEXT;
+       conn->state = IO_NEXT;
        conn->duplex = old;
        conn->timeout = NULL;
        if (!add_duplex(conn)) {
@@ -144,7 +144,7 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len,
        conn->next = cb;
        conn->next_arg = arg;
        conn->pollflag = POLLOUT;
-       return to_ioplan(IO);
+       return to_ioplan(IO_IO);
 }
 
 static enum io_result do_read(struct io_conn *conn)
@@ -171,7 +171,7 @@ struct io_plan *io_read_(struct io_conn *conn, void *data, size_t len,
        conn->next = cb;
        conn->next_arg = arg;
        conn->pollflag = POLLIN;
-       return to_ioplan(IO);
+       return to_ioplan(IO_IO);
 }
 
 static enum io_result do_read_partial(struct io_conn *conn)
@@ -195,7 +195,7 @@ struct io_plan *io_read_partial_(struct io_conn *conn, void *data, size_t *len,
        conn->next = cb;
        conn->next_arg = arg;
        conn->pollflag = POLLIN;
-       return to_ioplan(IO);
+       return to_ioplan(IO_IO);
 }
 
 static enum io_result do_write_partial(struct io_conn *conn)
@@ -220,13 +220,13 @@ struct io_plan *io_write_partial_(struct io_conn *conn,
        conn->next = cb;
        conn->next_arg = arg;
        conn->pollflag = POLLOUT;
-       return to_ioplan(IO);
+       return to_ioplan(IO_IO);
 }
 
 struct io_plan *io_idle(struct io_conn *conn)
 {
        conn->pollflag = 0;
-       return to_ioplan(IDLE);
+       return to_ioplan(IO_IDLE);
 }
 
 void io_wake_(struct io_conn *conn,
@@ -234,12 +234,12 @@ void io_wake_(struct io_conn *conn,
 
 {
        /* It might have finished, but we haven't called its finish() yet. */
-       if (conn->state == FINISHED)
+       if (conn->state == IO_FINISHED)
                return;
-       assert(conn->state == IDLE);
+       assert(conn->state == IO_IDLE);
        conn->next = fn;
        conn->next_arg = arg;
-       backend_set_state(conn, to_ioplan(NEXT));
+       backend_set_state(conn, to_ioplan(IO_NEXT));
 }
 
 static struct io_plan *do_next(struct io_conn *conn)
@@ -251,7 +251,7 @@ static struct io_plan *do_next(struct io_conn *conn)
 
 struct io_plan *do_ready(struct io_conn *conn)
 {
-       assert(conn->state == IO);
+       assert(conn->state == IO_IO);
        switch (conn->io(conn)) {
        case RESULT_CLOSE:
                return io_close(conn, NULL);
@@ -268,7 +268,7 @@ struct io_plan *do_ready(struct io_conn *conn)
 /* Close the connection, we're done. */
 struct io_plan *io_close(struct io_conn *conn, void *arg)
 {
-       return to_ioplan(FINISHED);
+       return to_ioplan(IO_FINISHED);
 }
 
 /* Exit the loop, returning this (non-NULL) arg. */
@@ -280,5 +280,5 @@ struct io_plan *io_break_(struct io_conn *conn, void *ret,
        conn->next = fn;
        conn->next_arg = arg;
 
-       return to_ioplan(NEXT);
+       return to_ioplan(IO_NEXT);
 }
index 5982ef1535e363723ac4904729fa824e1d718855..918e9f270e677e1dcfe83698232422e947172294 100644 (file)
@@ -101,9 +101,9 @@ static void del_conn(struct io_conn *conn)
                conn->duplex->duplex = NULL;
        } else
                del_fd(&conn->fd);
-       if (conn->state == FINISHED)
+       if (conn->state == IO_FINISHED)
                num_finished--;
-       else if (conn->state == NEXT)
+       else if (conn->state == IO_NEXT)
                num_next--;
 }
 
@@ -130,9 +130,9 @@ void backend_set_state(struct io_conn *conn, struct io_plan *plan)
        if (pfd->events)
                num_waiting++;
 
-       if (state == NEXT)
+       if (state == IO_NEXT)
                num_next++;
-       else if (state == FINISHED)
+       else if (state == IO_FINISHED)
                num_finished++;
 
        conn->state = state;
@@ -169,11 +169,11 @@ static void finish_and_next(bool finished_only)
                        continue;
                c = (void *)fds[i];
                for (duplex = c->duplex; c; c = duplex, duplex = NULL) {
-                       if (c->state == FINISHED) {
+                       if (c->state == IO_FINISHED) {
                                del_conn(c);
                                free(c);
                                i--;
-                       } else if (!finished_only && c->state == NEXT) {
+                       } else if (!finished_only && c->state == IO_NEXT) {
                                backend_set_state(c, c->next(c, c->next_arg));
                                num_next--;
                        }