Commit bafb5201 authored by Rusty Russell's avatar Rusty Russell

ccan/io: make enum io_state namespace-safe.

Ready for exposure.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent bfb80c56
......@@ -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)
......
......@@ -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);
}
......@@ -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--;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment