Commit 7f4e5627 authored by Rusty Russell's avatar Rusty Russell

ccan/io: put explicit poll flags in the plan.

Weaning off enum io_state, to allow custom ones.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 09989550
...@@ -77,6 +77,7 @@ struct io_conn { ...@@ -77,6 +77,7 @@ struct io_conn {
struct io_conn *duplex; struct io_conn *duplex;
struct io_timeout *timeout; struct io_timeout *timeout;
int pollflag; /* 0, POLLIN or POLLOUT */
enum io_state state; enum io_state state;
union { union {
struct io_state_read read; struct io_state_read read;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <poll.h>
void *io_loop_return; void *io_loop_return;
...@@ -56,6 +57,7 @@ struct io_conn *io_new_conn_(int fd, ...@@ -56,6 +57,7 @@ struct io_conn *io_new_conn_(int fd,
conn->fd.next = start; conn->fd.next = start;
conn->fd.finish = finish; conn->fd.finish = finish;
conn->fd.finish_arg = conn->fd.next_arg = arg; conn->fd.finish_arg = conn->fd.next_arg = arg;
conn->pollflag = 0;
conn->state = NEXT; conn->state = NEXT;
conn->duplex = NULL; conn->duplex = NULL;
conn->timeout = NULL; conn->timeout = NULL;
...@@ -84,6 +86,7 @@ struct io_conn *io_duplex_(struct io_conn *old, ...@@ -84,6 +86,7 @@ struct io_conn *io_duplex_(struct io_conn *old,
conn->fd.next = start; conn->fd.next = start;
conn->fd.finish = finish; conn->fd.finish = finish;
conn->fd.finish_arg = conn->fd.next_arg = arg; conn->fd.finish_arg = conn->fd.next_arg = arg;
conn->pollflag = 0;
conn->state = NEXT; conn->state = NEXT;
conn->duplex = old; conn->duplex = old;
conn->timeout = NULL; conn->timeout = NULL;
...@@ -125,6 +128,7 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len, ...@@ -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->u.write.len = len;
conn->fd.next = cb; conn->fd.next = cb;
conn->fd.next_arg = arg; conn->fd.next_arg = arg;
conn->pollflag = POLLOUT;
return to_ioplan(WRITE); return to_ioplan(WRITE);
} }
...@@ -137,6 +141,7 @@ struct io_plan *io_read_(struct io_conn *conn, void *data, size_t len, ...@@ -137,6 +141,7 @@ struct io_plan *io_read_(struct io_conn *conn, void *data, size_t len,
conn->u.read.len = len; conn->u.read.len = len;
conn->fd.next = cb; conn->fd.next = cb;
conn->fd.next_arg = arg; conn->fd.next_arg = arg;
conn->pollflag = POLLIN;
return to_ioplan(READ); return to_ioplan(READ);
} }
...@@ -149,6 +154,7 @@ struct io_plan *io_read_partial_(struct io_conn *conn, void *data, size_t *len, ...@@ -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->u.readpart.lenp = len;
conn->fd.next = cb; conn->fd.next = cb;
conn->fd.next_arg = arg; conn->fd.next_arg = arg;
conn->pollflag = POLLIN;
return to_ioplan(READPART); return to_ioplan(READPART);
} }
...@@ -162,11 +168,13 @@ struct io_plan *io_write_partial_(struct io_conn *conn, ...@@ -162,11 +168,13 @@ struct io_plan *io_write_partial_(struct io_conn *conn,
conn->u.writepart.lenp = len; conn->u.writepart.lenp = len;
conn->fd.next = cb; conn->fd.next = cb;
conn->fd.next_arg = arg; conn->fd.next_arg = arg;
conn->pollflag = POLLOUT;
return to_ioplan(WRITEPART); return to_ioplan(WRITEPART);
} }
struct io_plan *io_idle(struct io_conn *conn) struct io_plan *io_idle(struct io_conn *conn)
{ {
conn->pollflag = 0;
return to_ioplan(IDLE); return to_ioplan(IDLE);
} }
......
...@@ -112,20 +112,6 @@ void del_listener(struct io_listener *l) ...@@ -112,20 +112,6 @@ void del_listener(struct io_listener *l)
del_fd(&l->fd); 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) void backend_set_state(struct io_conn *conn, struct io_plan *plan)
{ {
enum io_state state = from_ioplan(plan); enum io_state state = from_ioplan(plan);
...@@ -134,9 +120,9 @@ void backend_set_state(struct io_conn *conn, struct io_plan *plan) ...@@ -134,9 +120,9 @@ void backend_set_state(struct io_conn *conn, struct io_plan *plan)
if (pfd->events) if (pfd->events)
num_waiting--; num_waiting--;
pfd->events = pollmask(state); pfd->events = conn->pollflag;
if (conn->duplex) { if (conn->duplex) {
int mask = pollmask(conn->duplex->state); int mask = conn->duplex->pollflag;
/* You can't *both* read/write. */ /* You can't *both* read/write. */
assert(!mask || pfd->events != mask); assert(!mask || pfd->events != mask);
pfd->events |= mask; pfd->events |= mask;
...@@ -282,7 +268,7 @@ void *io_loop(void) ...@@ -282,7 +268,7 @@ void *io_loop(void)
} else if (events & (POLLIN|POLLOUT)) { } else if (events & (POLLIN|POLLOUT)) {
r--; r--;
if (c->duplex) { if (c->duplex) {
int mask = pollmask(c->duplex->state); int mask = c->duplex->pollflag;
if (events & mask) { if (events & mask) {
ready(c->duplex); ready(c->duplex);
events &= ~mask; events &= ~mask;
......
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