Weaning off enum io_state, to allow custom ones.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
struct io_conn *duplex;
struct io_timeout *timeout;
+ int pollflag; /* 0, POLLIN or POLLOUT */
enum io_state state;
union {
struct io_state_read read;
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
+#include <poll.h>
void *io_loop_return;
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;
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;
conn->u.write.len = len;
conn->fd.next = cb;
conn->fd.next_arg = arg;
+ conn->pollflag = POLLOUT;
return to_ioplan(WRITE);
}
conn->u.read.len = len;
conn->fd.next = cb;
conn->fd.next_arg = arg;
+ conn->pollflag = POLLIN;
return to_ioplan(READ);
}
conn->u.readpart.lenp = len;
conn->fd.next = cb;
conn->fd.next_arg = arg;
+ conn->pollflag = POLLIN;
return to_ioplan(READPART);
}
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);
}
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);
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;
} 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;