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 {
struct io_conn *duplex;
struct io_timeout *timeout;
int pollflag; /* 0, POLLIN or POLLOUT */
enum io_state state;
union {
struct io_state_read read;
......
......@@ -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);
}
......
......@@ -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;
......
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