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

ccan/io: rename io_op to io_plan.

This is a better description, since it's I/O we plan to do next.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 1fe2db9c
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
* }; * };
* *
* // This reads from stdin. * // This reads from stdin.
* static struct io_op *wake_writer(struct io_conn *, struct stdin_buffer *); * static struct io_plan *wake_writer(struct io_conn *, struct stdin_buffer *);
* // This writes the stdin buffer to the child. * // This writes the stdin buffer to the child.
* static struct io_op *write_to_child(struct io_conn *c, * static struct io_plan *write_to_child(struct io_conn *c,
* struct stdin_buffer *b); * struct stdin_buffer *b);
* static struct io_op *read_stdin(struct io_conn *c, struct stdin_buffer *b) * static struct io_plan *read_stdin(struct io_conn *c, struct stdin_buffer *b)
* { * {
* assert(c == b->reader); * assert(c == b->reader);
* b->len = sizeof(b->inbuf); * b->len = sizeof(b->inbuf);
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
* io_next(c, wake_writer, b)); * io_next(c, wake_writer, b));
* } * }
* *
* static struct io_op *wake_writer(struct io_conn *c, struct stdin_buffer *b) * static struct io_plan *wake_writer(struct io_conn *c, struct stdin_buffer *b)
* { * {
* assert(c == b->reader); * assert(c == b->reader);
* io_wake(b->writer, write_to_child, b); * io_wake(b->writer, write_to_child, b);
...@@ -58,14 +58,14 @@ ...@@ -58,14 +58,14 @@
* b->reader = NULL; * b->reader = NULL;
* } * }
* *
* static struct io_op *wake_reader(struct io_conn *c, struct stdin_buffer *b) * static struct io_plan *wake_reader(struct io_conn *c, struct stdin_buffer *b)
* { * {
* assert(c == b->writer); * assert(c == b->writer);
* io_wake(b->reader, read_stdin, b); * io_wake(b->reader, read_stdin, b);
* return io_idle(c); * return io_idle(c);
* } * }
* *
* static struct io_op *write_to_child(struct io_conn *conn, * static struct io_plan *write_to_child(struct io_conn *conn,
* struct stdin_buffer *b) * struct stdin_buffer *b)
* { * {
* assert(conn == b->writer); * assert(conn == b->writer);
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
* return io_write(b->inbuf, b->len, io_next(conn, wake_reader, b)); * return io_write(b->inbuf, b->len, io_next(conn, wake_reader, b));
* } * }
* *
* static struct io_op *start_writer(struct io_conn *conn, * static struct io_plan *start_writer(struct io_conn *conn,
* struct stdin_buffer *b) * struct stdin_buffer *b)
* { * {
* assert(conn == b->writer); * assert(conn == b->writer);
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
* } * }
* *
* // This reads from the child and saves it into buffer. * // This reads from the child and saves it into buffer.
* static struct io_op *read_from_child(struct io_conn *conn, * static struct io_plan *read_from_child(struct io_conn *conn,
* struct buffer *b) * struct buffer *b)
* { * {
* b->off += b->rlen; * b->off += b->rlen;
......
...@@ -9,7 +9,7 @@ struct fd { ...@@ -9,7 +9,7 @@ struct fd {
bool listener; bool listener;
size_t backend_info; size_t backend_info;
struct io_op *(*next)(struct io_conn *, void *arg); struct io_plan *(*next)(struct io_conn *, void *arg);
void *next_arg; void *next_arg;
void (*finish)(struct io_conn *, void *arg); void (*finish)(struct io_conn *, void *arg);
...@@ -37,7 +37,7 @@ enum io_state { ...@@ -37,7 +37,7 @@ enum io_state {
PROCESSING /* We expect them to change this now. */ PROCESSING /* We expect them to change this now. */
}; };
static inline enum io_state from_ioop(struct io_op *op) static inline enum io_state from_ioplan(struct io_plan *op)
{ {
return (enum io_state)(long)op; return (enum io_state)(long)op;
} }
...@@ -66,7 +66,7 @@ struct io_timeout { ...@@ -66,7 +66,7 @@ struct io_timeout {
struct timer timer; struct timer timer;
struct io_conn *conn; struct io_conn *conn;
struct io_op *(*next)(struct io_conn *, void *arg); struct io_plan *(*next)(struct io_conn *, void *arg);
void *next_arg; void *next_arg;
}; };
...@@ -97,9 +97,9 @@ bool add_listener(struct io_listener *l); ...@@ -97,9 +97,9 @@ bool add_listener(struct io_listener *l);
bool add_conn(struct io_conn *c); bool add_conn(struct io_conn *c);
bool add_duplex(struct io_conn *c); bool add_duplex(struct io_conn *c);
void del_listener(struct io_listener *l); void del_listener(struct io_listener *l);
void backend_set_state(struct io_conn *conn, struct io_op *op); void backend_set_state(struct io_conn *conn, struct io_plan *op);
void backend_add_timeout(struct io_conn *conn, struct timespec ts); void backend_add_timeout(struct io_conn *conn, struct timespec ts);
void backend_del_timeout(struct io_conn *conn); void backend_del_timeout(struct io_conn *conn);
struct io_op *do_ready(struct io_conn *conn); struct io_plan *do_ready(struct io_conn *conn);
#endif /* CCAN_IO_BACKEND_H */ #endif /* CCAN_IO_BACKEND_H */
...@@ -25,21 +25,21 @@ struct client { ...@@ -25,21 +25,21 @@ struct client {
char reply_buffer[REPLY_SIZE]; char reply_buffer[REPLY_SIZE];
}; };
static struct io_op *write_reply(struct io_conn *conn, struct client *client); static struct io_plan *write_reply(struct io_conn *conn, struct client *client);
static struct io_op *read_request(struct io_conn *conn, struct client *client) static struct io_plan *read_request(struct io_conn *conn, struct client *client)
{ {
return io_read(client->request_buffer, REQUEST_SIZE, return io_read(client->request_buffer, REQUEST_SIZE,
io_next(conn, write_reply, client)); io_next(conn, write_reply, client));
} }
/* once we're done, loop again. */ /* once we're done, loop again. */
static struct io_op *write_complete(struct io_conn *conn, struct client *client) static struct io_plan *write_complete(struct io_conn *conn, struct client *client)
{ {
completed++; completed++;
return read_request(conn, client); return read_request(conn, client);
} }
static struct io_op *write_reply(struct io_conn *conn, struct client *client) static struct io_plan *write_reply(struct io_conn *conn, struct client *client)
{ {
return io_write(client->reply_buffer, REPLY_SIZE, return io_write(client->reply_buffer, REPLY_SIZE,
io_next(conn, write_complete, client)); io_next(conn, write_complete, client));
...@@ -106,12 +106,12 @@ static void sigalarm(int sig) ...@@ -106,12 +106,12 @@ static void sigalarm(int sig)
write(timeout[1], "1", 1); write(timeout[1], "1", 1);
} }
static struct io_op *do_timeout(struct io_conn *conn, char *buf) static struct io_plan *do_timeout(struct io_conn *conn, char *buf)
{ {
return io_break(conn, NULL); return io_break(conn, NULL);
} }
static struct io_op *do_timeout_read(struct io_conn *conn, char *buf) static struct io_plan *do_timeout_read(struct io_conn *conn, char *buf)
{ {
return io_read(buf, 1, io_next(conn, do_timeout, buf)); return io_read(buf, 1, io_next(conn, do_timeout, buf));
} }
......
...@@ -25,28 +25,28 @@ struct client { ...@@ -25,28 +25,28 @@ struct client {
char *request_buffer; char *request_buffer;
}; };
static struct io_op *write_reply(struct io_conn *conn, struct client *client); static struct io_plan *write_reply(struct io_conn *conn, struct client *client);
static struct io_op *read_body(struct io_conn *conn, struct client *client) static struct io_plan *read_body(struct io_conn *conn, struct client *client)
{ {
assert(client->len <= REQUEST_MAX); assert(client->len <= REQUEST_MAX);
return io_read(client->request_buffer, client->len, return io_read(client->request_buffer, client->len,
io_next(conn, write_reply, client)); io_next(conn, write_reply, client));
} }
static struct io_op *read_header(struct io_conn *conn, struct client *client) static struct io_plan *read_header(struct io_conn *conn, struct client *client)
{ {
return io_read(&client->len, sizeof(client->len), return io_read(&client->len, sizeof(client->len),
io_next(conn, read_body, client)); io_next(conn, read_body, client));
} }
/* once we're done, loop again. */ /* once we're done, loop again. */
static struct io_op *write_complete(struct io_conn *conn, struct client *client) static struct io_plan *write_complete(struct io_conn *conn, struct client *client)
{ {
completed++; completed++;
return read_header(conn, client); return read_header(conn, client);
} }
static struct io_op *write_reply(struct io_conn *conn, struct client *client) static struct io_plan *write_reply(struct io_conn *conn, struct client *client)
{ {
return io_write(&client->len, sizeof(client->len), return io_write(&client->len, sizeof(client->len),
io_next(conn, write_complete, client)); io_next(conn, write_complete, client));
...@@ -112,12 +112,12 @@ static void sigalarm(int sig) ...@@ -112,12 +112,12 @@ static void sigalarm(int sig)
write(timeout[1], "1", 1); write(timeout[1], "1", 1);
} }
static struct io_op *do_timeout(struct io_conn *conn, char *buf) static struct io_plan *do_timeout(struct io_conn *conn, char *buf)
{ {
return io_break(conn, NULL); return io_break(conn, NULL);
} }
static struct io_op *do_timeout_read(struct io_conn *conn, char *buf) static struct io_plan *do_timeout_read(struct io_conn *conn, char *buf)
{ {
return io_read(buf, 1, io_next(conn, do_timeout, buf)); return io_read(buf, 1, io_next(conn, do_timeout, buf));
} }
......
...@@ -16,10 +16,10 @@ struct buffer { ...@@ -16,10 +16,10 @@ struct buffer {
char buf[32]; char buf[32];
}; };
static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf); static struct io_plan *poke_writer(struct io_conn *conn, struct buffer *buf);
static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf); static struct io_plan *poke_reader(struct io_conn *conn, struct buffer *buf);
static struct io_op *do_read(struct io_conn *conn, struct buffer *buf) static struct io_plan *do_read(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
...@@ -27,7 +27,7 @@ static struct io_op *do_read(struct io_conn *conn, struct buffer *buf) ...@@ -27,7 +27,7 @@ static struct io_op *do_read(struct io_conn *conn, struct buffer *buf)
io_next(conn, poke_writer, buf)); io_next(conn, poke_writer, buf));
} }
static struct io_op *do_write(struct io_conn *conn, struct buffer *buf) static struct io_plan *do_write(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->writer); assert(conn == buf->writer);
...@@ -35,7 +35,7 @@ static struct io_op *do_write(struct io_conn *conn, struct buffer *buf) ...@@ -35,7 +35,7 @@ static struct io_op *do_write(struct io_conn *conn, struct buffer *buf)
io_next(conn, poke_reader, buf)); io_next(conn, poke_reader, buf));
} }
static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf) static struct io_plan *poke_writer(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
...@@ -49,7 +49,7 @@ static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf) ...@@ -49,7 +49,7 @@ static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf)
return io_idle(conn); return io_idle(conn);
} }
static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf) static struct io_plan *poke_reader(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->writer); assert(conn == buf->writer);
/* You read. */ /* You read. */
...@@ -62,7 +62,7 @@ static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf) ...@@ -62,7 +62,7 @@ static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf)
return io_idle(conn); return io_idle(conn);
} }
static struct io_op *reader(struct io_conn *conn, struct buffer *buf) static struct io_plan *reader(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
void *io_loop_return; void *io_loop_return;
struct io_listener *io_new_listener_(int fd, struct io_listener *io_new_listener_(int fd,
struct io_op *(*start)(struct io_conn *, struct io_plan *(*start)(struct io_conn *,
void *arg), void *arg),
void (*finish)(struct io_conn *, void *), void (*finish)(struct io_conn *, void *),
void *arg) void *arg)
...@@ -42,7 +42,7 @@ void io_close_listener(struct io_listener *l) ...@@ -42,7 +42,7 @@ void io_close_listener(struct io_listener *l)
} }
struct io_conn *io_new_conn_(int fd, struct io_conn *io_new_conn_(int fd,
struct io_op *(*start)(struct io_conn *, void *), struct io_plan *(*start)(struct io_conn *, void *),
void (*finish)(struct io_conn *, void *), void (*finish)(struct io_conn *, void *),
void *arg) void *arg)
{ {
...@@ -67,7 +67,7 @@ struct io_conn *io_new_conn_(int fd, ...@@ -67,7 +67,7 @@ struct io_conn *io_new_conn_(int fd,
} }
struct io_conn *io_duplex_(struct io_conn *old, struct io_conn *io_duplex_(struct io_conn *old,
struct io_op *(*start)(struct io_conn *, void *), struct io_plan *(*start)(struct io_conn *, void *),
void (*finish)(struct io_conn *, void *), void (*finish)(struct io_conn *, void *),
void *arg) void *arg)
{ {
...@@ -101,9 +101,9 @@ static inline struct io_next *to_ionext(struct io_conn *conn) ...@@ -101,9 +101,9 @@ static inline struct io_next *to_ionext(struct io_conn *conn)
return (struct io_next *)conn; return (struct io_next *)conn;
} }
static inline struct io_op *to_ioop(enum io_state state) static inline struct io_plan *to_ioplan(enum io_state state)
{ {
return (struct io_op *)(long)state; return (struct io_plan *)(long)state;
} }
static inline struct io_conn *from_ionext(struct io_next *next) static inline struct io_conn *from_ionext(struct io_next *next)
...@@ -112,7 +112,7 @@ static inline struct io_conn *from_ionext(struct io_next *next) ...@@ -112,7 +112,7 @@ static inline struct io_conn *from_ionext(struct io_next *next)
} }
struct io_next *io_next_(struct io_conn *conn, struct io_next *io_next_(struct io_conn *conn,
struct io_op *(*next)(struct io_conn *, void *), struct io_plan *(*next)(struct io_conn *, void *),
void *arg) void *arg)
{ {
conn->fd.next = next; conn->fd.next = next;
...@@ -122,7 +122,7 @@ struct io_next *io_next_(struct io_conn *conn, ...@@ -122,7 +122,7 @@ struct io_next *io_next_(struct io_conn *conn,
} }
bool io_timeout_(struct io_conn *conn, struct timespec ts, bool io_timeout_(struct io_conn *conn, struct timespec ts,
struct io_op *(*next)(struct io_conn *, void *), void *arg) struct io_plan *(*next)(struct io_conn *, void *), void *arg)
{ {
if (!conn->timeout) { if (!conn->timeout) {
conn->timeout = malloc(sizeof(*conn->timeout)); conn->timeout = malloc(sizeof(*conn->timeout));
...@@ -138,48 +138,48 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts, ...@@ -138,48 +138,48 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts,
} }
/* Queue some data to be written. */ /* Queue some data to be written. */
struct io_op *io_write(const void *data, size_t len, struct io_next *next) struct io_plan *io_write(const void *data, size_t len, struct io_next *next)
{ {
struct io_conn *conn = from_ionext(next); struct io_conn *conn = from_ionext(next);
conn->u.write.buf = data; conn->u.write.buf = data;
conn->u.write.len = len; conn->u.write.len = len;
return to_ioop(WRITE); return to_ioplan(WRITE);
} }
/* Queue a request to read into a buffer. */ /* Queue a request to read into a buffer. */
struct io_op *io_read(void *data, size_t len, struct io_next *next) struct io_plan *io_read(void *data, size_t len, struct io_next *next)
{ {
struct io_conn *conn = from_ionext(next); struct io_conn *conn = from_ionext(next);
conn->u.read.buf = data; conn->u.read.buf = data;
conn->u.read.len = len; conn->u.read.len = len;
return to_ioop(READ); return to_ioplan(READ);
} }
/* Queue a partial request to read into a buffer. */ /* Queue a partial request to read into a buffer. */
struct io_op *io_read_partial(void *data, size_t *len, struct io_next *next) struct io_plan *io_read_partial(void *data, size_t *len, struct io_next *next)
{ {
struct io_conn *conn = from_ionext(next); struct io_conn *conn = from_ionext(next);
conn->u.readpart.buf = data; conn->u.readpart.buf = data;
conn->u.readpart.lenp = len; conn->u.readpart.lenp = len;
return to_ioop(READPART); return to_ioplan(READPART);
} }
/* Queue a partial write request. */ /* Queue a partial write request. */
struct io_op *io_write_partial(const void *data, size_t *len, struct io_next *next) struct io_plan *io_write_partial(const void *data, size_t *len, struct io_next *next)
{ {
struct io_conn *conn = from_ionext(next); struct io_conn *conn = from_ionext(next);
conn->u.writepart.buf = data; conn->u.writepart.buf = data;
conn->u.writepart.lenp = len; conn->u.writepart.lenp = len;
return to_ioop(WRITEPART); return to_ioplan(WRITEPART);
} }
struct io_op *io_idle(struct io_conn *conn) struct io_plan *io_idle(struct io_conn *conn)
{ {
return to_ioop(IDLE); return to_ioplan(IDLE);
} }
void io_wake_(struct io_conn *conn, void io_wake_(struct io_conn *conn,
struct io_op *(*next)(struct io_conn *, void *), void *arg) struct io_plan *(*next)(struct io_conn *, void *), void *arg)
{ {
/* It might have finished, but we haven't called its finish() yet. */ /* It might have finished, but we haven't called its finish() yet. */
...@@ -188,17 +188,17 @@ void io_wake_(struct io_conn *conn, ...@@ -188,17 +188,17 @@ void io_wake_(struct io_conn *conn,
assert(conn->state == IDLE); assert(conn->state == IDLE);
conn->fd.next = next; conn->fd.next = next;
conn->fd.next_arg = arg; conn->fd.next_arg = arg;
backend_set_state(conn, to_ioop(NEXT)); backend_set_state(conn, to_ioplan(NEXT));
} }
static struct io_op *do_next(struct io_conn *conn) static struct io_plan *do_next(struct io_conn *conn)
{ {
if (timeout_active(conn)) if (timeout_active(conn))
backend_del_timeout(conn); backend_del_timeout(conn);
return conn->fd.next(conn, conn->fd.next_arg); return conn->fd.next(conn, conn->fd.next_arg);
} }
struct io_op *do_ready(struct io_conn *conn) struct io_plan *do_ready(struct io_conn *conn)
{ {
ssize_t ret; ssize_t ret;
bool finished; bool finished;
...@@ -243,20 +243,20 @@ struct io_op *do_ready(struct io_conn *conn) ...@@ -243,20 +243,20 @@ struct io_op *do_ready(struct io_conn *conn)
if (finished) if (finished)
return do_next(conn); return do_next(conn);
return to_ioop(conn->state); return to_ioplan(conn->state);
} }
/* Useful next functions. */ /* Useful next functions. */
/* Close the connection, we're done. */ /* Close the connection, we're done. */
struct io_op *io_close(struct io_conn *conn, void *arg) struct io_plan *io_close(struct io_conn *conn, void *arg)
{ {
return to_ioop(FINISHED); return to_ioplan(FINISHED);
} }
/* Exit the loop, returning this (non-NULL) arg. */ /* Exit the loop, returning this (non-NULL) arg. */
struct io_op *io_break(void *arg, struct io_next *next) struct io_plan *io_break(void *arg, struct io_next *next)
{ {
io_loop_return = arg; io_loop_return = arg;
return to_ioop(NEXT); return to_ioplan(NEXT);
} }
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
#include <unistd.h> #include <unistd.h>
/** /**
* struct io_op - pointer to return from io functions. * struct io_plan - pointer to return from a setup function.
* *
* This undefined structure is just to help the compiler check that you * A plan of what IO to do, when.
* really do return the result of an io-queueing method.
*/ */
struct io_op; struct io_plan;
/** /**
* struct io_next - pointer to what we're going to do next. * struct io_next - pointer to what we're going to do next.
...@@ -40,13 +39,13 @@ struct io_next; ...@@ -40,13 +39,13 @@ struct io_next;
*/ */
#define io_new_conn(fd, start, finish, arg) \ #define io_new_conn(fd, start, finish, arg) \
io_new_conn_((fd), \ io_new_conn_((fd), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), struct io_conn *), \ (start), (arg), struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), (arg), \ typesafe_cb_preargs(void, void *, (finish), (arg), \
struct io_conn *), \ struct io_conn *), \
(arg)) (arg))
struct io_conn *io_new_conn_(int fd, struct io_conn *io_new_conn_(int fd,
struct io_op *(*start)(struct io_conn *, void *), struct io_plan *(*start)(struct io_conn *, void *),
void (*finish)(struct io_conn *, void *), void (*finish)(struct io_conn *, void *),
void *arg); void *arg);
...@@ -64,14 +63,14 @@ struct io_conn *io_new_conn_(int fd, ...@@ -64,14 +63,14 @@ struct io_conn *io_new_conn_(int fd,
*/ */
#define io_new_listener(fd, start, finish, arg) \ #define io_new_listener(fd, start, finish, arg) \
io_new_listener_((fd), \ io_new_listener_((fd), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), \ (start), (arg), \
struct io_conn *), \ struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), \ typesafe_cb_preargs(void, void *, (finish), \
(arg), struct io_conn *), \ (arg), struct io_conn *), \
(arg)) (arg))
struct io_listener *io_new_listener_(int fd, struct io_listener *io_new_listener_(int fd,
struct io_op *(*start)(struct io_conn *, struct io_plan *(*start)(struct io_conn *,
void *arg), void *arg),
void (*finish)(struct io_conn *, void (*finish)(struct io_conn *,
void *arg), void *arg),
...@@ -97,7 +96,7 @@ void io_close_listener(struct io_listener *listener); ...@@ -97,7 +96,7 @@ void io_close_listener(struct io_listener *listener);
* *
* Note that the I/O may actually be done immediately. * Note that the I/O may actually be done immediately.
*/ */
struct io_op *io_write(const void *data, size_t len, struct io_next *next); struct io_plan *io_write(const void *data, size_t len, struct io_next *next);
/** /**
* io_read - queue buffer to be read. * io_read - queue buffer to be read.
...@@ -111,7 +110,7 @@ struct io_op *io_write(const void *data, size_t len, struct io_next *next); ...@@ -111,7 +110,7 @@ struct io_op *io_write(const void *data, size_t len, struct io_next *next);
* *
* Note that the I/O may actually be done immediately. * Note that the I/O may actually be done immediately.
*/ */
struct io_op *io_read(void *data, size_t len, struct io_next *next); struct io_plan *io_read(void *data, size_t len, struct io_next *next);
/** /**
* io_read_partial - queue buffer to be read (partial OK). * io_read_partial - queue buffer to be read (partial OK).
...@@ -125,7 +124,7 @@ struct io_op *io_read(void *data, size_t len, struct io_next *next); ...@@ -125,7 +124,7 @@ struct io_op *io_read(void *data, size_t len, struct io_next *next);
* *
* Note that the I/O may actually be done immediately. * Note that the I/O may actually be done immediately.
*/ */
struct io_op *io_read_partial(void *data, size_t *len, struct io_next *next); struct io_plan *io_read_partial(void *data, size_t *len, struct io_next *next);
/** /**
* io_write_partial - queue data to be written (partial OK). * io_write_partial - queue data to be written (partial OK).
...@@ -139,7 +138,7 @@ struct io_op *io_read_partial(void *data, size_t *len, struct io_next *next); ...@@ -139,7 +138,7 @@ struct io_op *io_read_partial(void *data, size_t *len, struct io_next *next);
* *
* Note that the I/O may actually be done immediately. * Note that the I/O may actually be done immediately.
*/ */
struct io_op *io_write_partial(const void *data, size_t *len, struct io_plan *io_write_partial(const void *data, size_t *len,
struct io_next *next); struct io_next *next);
/** /**
...@@ -150,7 +149,7 @@ struct io_op *io_write_partial(const void *data, size_t *len, ...@@ -150,7 +149,7 @@ struct io_op *io_write_partial(const void *data, size_t *len,
* later call io_read/io_write etc. (or io_close) on it, in which case * later call io_read/io_write etc. (or io_close) on it, in which case
* it will do that. * it will do that.
*/ */
struct io_op *io_idle(struct io_conn *conn); struct io_plan *io_idle(struct io_conn *conn);
/** /**
* io_timeout - set timeout function if the callback doesn't fire. * io_timeout - set timeout function if the callback doesn't fire.
...@@ -168,13 +167,13 @@ struct io_op *io_idle(struct io_conn *conn); ...@@ -168,13 +167,13 @@ struct io_op *io_idle(struct io_conn *conn);
*/ */
#define io_timeout(conn, ts, next, arg) \ #define io_timeout(conn, ts, next, arg) \
io_timeout_((conn), (ts), \ io_timeout_((conn), (ts), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), \ (next), (arg), \
struct io_conn *), \ struct io_conn *), \
(arg)) (arg))
bool io_timeout_(struct io_conn *conn, struct timespec ts, bool io_timeout_(struct io_conn *conn, struct timespec ts,
struct io_op *(*next)(struct io_conn *, void *), void *arg); struct io_plan *(*next)(struct io_conn *, void *), void *arg);
/** /**
* io_duplex - split an fd into two connections. * io_duplex - split an fd into two connections.
...@@ -192,14 +191,14 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts, ...@@ -192,14 +191,14 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts,
*/ */
#define io_duplex(conn, start, finish, arg) \ #define io_duplex(conn, start, finish, arg) \
io_duplex_((conn), \ io_duplex_((conn), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), struct io_conn *), \ (start), (arg), struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), (arg), \ typesafe_cb_preargs(void, void *, (finish), (arg), \
struct io_conn *), \ struct io_conn *), \
(arg)) (arg))
struct io_conn *io_duplex_(struct io_conn *conn, struct io_conn *io_duplex_(struct io_conn *conn,
struct io_op *(*start)(struct io_conn *, void *), struct io_plan *(*start)(struct io_conn *, void *),
void (*finish)(struct io_conn *, void *), void (*finish)(struct io_conn *, void *),
void *arg); void *arg);
...@@ -214,11 +213,11 @@ struct io_conn *io_duplex_(struct io_conn *conn, ...@@ -214,11 +213,11 @@ struct io_conn *io_duplex_(struct io_conn *conn,
*/ */
#define io_wake(conn, next, arg) \ #define io_wake(conn, next, arg) \
io_wake_((conn), \ io_wake_((conn), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), struct io_conn *), \ (next), (arg), struct io_conn *), \
(arg)) (arg))
void io_wake_(struct io_conn *conn, void io_wake_(struct io_conn *conn,
struct io_op *(*next)(struct io_conn *, void *), void *arg); struct io_plan *(*next)(struct io_conn *, void *), void *arg);
/** /**
* io_break - return from io_loop() * io_break - return from io_loop()
...@@ -231,7 +230,7 @@ void io_wake_(struct io_conn *conn, ...@@ -231,7 +230,7 @@ void io_wake_(struct io_conn *conn,
* *
* If io_loop() is called again, then @next will be called. * If io_loop() is called again, then @next will be called.
*/ */
struct io_op *io_break(void *arg, struct io_next *next); struct io_plan *io_break(void *arg, struct io_next *next);
/** /**
* io_next - indicate what callback to call next. * io_next - indicate what callback to call next.
...@@ -249,11 +248,11 @@ struct io_op *io_break(void *arg, struct io_next *next); ...@@ -249,11 +248,11 @@ struct io_op *io_break(void *arg, struct io_next *next);
*/ */
#define io_next(conn, next, arg) \ #define io_next(conn, next, arg) \
io_next_((conn), \ io_next_((conn), \
typesafe_cb_preargs(struct io_op *, void *, \ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), struct io_conn *), \ (next), (arg), struct io_conn *), \
(arg)) (arg))
struct io_next *io_next_(struct io_conn *conn, struct io_next *io_next_(struct io_conn *conn,
struct io_op *(*next)(struct io_conn *, void *arg), struct io_plan *(*next)(struct io_conn *, void *arg),
void *arg); void *arg);
/* FIXME: io_recvfrom/io_sendto */ /* FIXME: io_recvfrom/io_sendto */
...@@ -269,7 +268,7 @@ struct io_next *io_next_(struct io_conn *conn, ...@@ -269,7 +268,7 @@ struct io_next *io_next_(struct io_conn *conn,
* It's common to 'return io_close(...)' from a @next function, but * It's common to 'return io_close(...)' from a @next function, but
* io_close can also be used as an argument to io_next(). * io_close can also be used as an argument to io_next().
*/ */
struct io_op *io_close(struct io_conn *, void *unused); struct io_plan *io_close(struct io_conn *, void *unused);
/** /**
* io_loop - process fds until all closed on io_break. * io_loop - process fds until all closed on io_break.
......
...@@ -126,9 +126,9 @@ static int pollmask(enum io_state state) ...@@ -126,9 +126,9 @@ static int pollmask(enum io_state state)
} }
} }
void backend_set_state(struct io_conn *conn, struct io_op *op) void backend_set_state(struct io_conn *conn, struct io_plan *plan)
{ {
enum io_state state = from_ioop(op); enum io_state state = from_ioplan(plan);
struct pollfd *pfd = &pollfds[conn->fd.backend_info]; struct pollfd *pfd = &pollfds[conn->fd.backend_info];
if (pfd->events) if (pfd->events)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
static struct io_op *start_ok(struct io_conn *conn, int *state) static struct io_plan *start_ok(struct io_conn *conn, int *state)
{ {
ok1(*state == 0); ok1(*state == 0);
(*state)++; (*state)++;
......
...@@ -11,7 +11,7 @@ struct data { ...@@ -11,7 +11,7 @@ struct data {
char buf[4]; char buf[4];
}; };
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -12,7 +12,7 @@ struct data { ...@@ -12,7 +12,7 @@ struct data {
char buf[4]; char buf[4];
}; };
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -12,7 +12,7 @@ struct data { ...@@ -12,7 +12,7 @@ struct data {
char *buf; char *buf;
}; };
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -12,7 +12,7 @@ struct data { ...@@ -12,7 +12,7 @@ struct data {
char *buf; char *buf;
}; };
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -16,14 +16,14 @@ struct data { ...@@ -16,14 +16,14 @@ struct data {
char buf[4]; char buf[4];
}; };
static struct io_op *do_read(struct io_conn *conn, struct data *d) static struct io_plan *do_read(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 2 || d->state == 3); ok1(d->state == 2 || d->state == 3);
d->state++; d->state++;
return io_read(d->buf, sizeof(d->buf), io_next(conn, io_close, d)); return io_read(d->buf, sizeof(d->buf), io_next(conn, io_close, d));
} }
static struct io_op *start_waker(struct io_conn *conn, struct data *d) static struct io_plan *start_waker(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 1); ok1(d->state == 1);
d->state++; d->state++;
...@@ -38,7 +38,7 @@ static void finish_waker(struct io_conn *conn, struct data *d) ...@@ -38,7 +38,7 @@ static void finish_waker(struct io_conn *conn, struct data *d)
d->state++; d->state++;
} }
static struct io_op *start_idle(struct io_conn *conn, struct data *d) static struct io_plan *start_idle(struct io_conn *conn, struct data *d)
{ {
int fd; int fd;
......
...@@ -11,14 +11,14 @@ struct data { ...@@ -11,14 +11,14 @@ struct data {
char buf[4]; char buf[4];
}; };
static struct io_op *do_read(struct io_conn *conn, struct data *d) static struct io_plan *do_read(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 1); ok1(d->state == 1);
d->state++; d->state++;
return io_read(d->buf, sizeof(d->buf), io_next(conn, io_close, d)); return io_read(d->buf, sizeof(d->buf), io_next(conn, io_close, d));
} }
static struct io_op *start_break(struct io_conn *conn, struct data *d) static struct io_plan *start_break(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -15,10 +15,10 @@ struct buffer { ...@@ -15,10 +15,10 @@ struct buffer {
char buf[32]; char buf[32];
}; };
static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf); static struct io_plan *poke_writer(struct io_conn *conn, struct buffer *buf);
static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf); static struct io_plan *poke_reader(struct io_conn *conn, struct buffer *buf);
static struct io_op *do_read(struct io_conn *conn, struct buffer *buf) static struct io_plan *do_read(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
...@@ -26,7 +26,7 @@ static struct io_op *do_read(struct io_conn *conn, struct buffer *buf) ...@@ -26,7 +26,7 @@ static struct io_op *do_read(struct io_conn *conn, struct buffer *buf)
io_next(conn, poke_writer, buf)); io_next(conn, poke_writer, buf));
} }
static struct io_op *do_write(struct io_conn *conn, struct buffer *buf) static struct io_plan *do_write(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->writer); assert(conn == buf->writer);
...@@ -34,7 +34,7 @@ static struct io_op *do_write(struct io_conn *conn, struct buffer *buf) ...@@ -34,7 +34,7 @@ static struct io_op *do_write(struct io_conn *conn, struct buffer *buf)
io_next(conn, poke_reader, buf)); io_next(conn, poke_reader, buf));
} }
static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf) static struct io_plan *poke_writer(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
...@@ -48,7 +48,7 @@ static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf) ...@@ -48,7 +48,7 @@ static struct io_op *poke_writer(struct io_conn *conn, struct buffer *buf)
return io_idle(conn); return io_idle(conn);
} }
static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf) static struct io_plan *poke_reader(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->writer); assert(conn == buf->writer);
/* You read. */ /* You read. */
...@@ -61,7 +61,7 @@ static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf) ...@@ -61,7 +61,7 @@ static struct io_op *poke_reader(struct io_conn *conn, struct buffer *buf)
return io_idle(conn); return io_idle(conn);
} }
static struct io_op *reader(struct io_conn *conn, struct buffer *buf) static struct io_plan *reader(struct io_conn *conn, struct buffer *buf)
{ {
assert(conn == buf->reader); assert(conn == buf->reader);
......
...@@ -18,13 +18,13 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -18,13 +18,13 @@ static void finish_ok(struct io_conn *conn, struct data *d)
d->state++; d->state++;
} }
static struct io_op *write_out(struct io_conn *conn, struct data *d) static struct io_plan *write_out(struct io_conn *conn, struct data *d)
{ {
d->state++; d->state++;
return io_write(d->wbuf, sizeof(d->wbuf), io_next(conn, io_close, d)); return io_write(d->wbuf, sizeof(d->wbuf), io_next(conn, io_close, d));
} }
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
static struct io_op *start(struct io_conn *conn, void *unused) static struct io_plan *start(struct io_conn *conn, void *unused)
{ {
return io_idle(conn); return io_idle(conn);
} }
......
...@@ -15,14 +15,14 @@ struct data { ...@@ -15,14 +15,14 @@ struct data {
}; };
static struct io_op *no_timeout(struct io_conn *conn, struct data *d) static struct io_plan *no_timeout(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 1); ok1(d->state == 1);
d->state++; d->state++;
return io_close(conn, d); return io_close(conn, d);
} }
static struct io_op *timeout(struct io_conn *conn, struct data *d) static struct io_plan *timeout(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 1); ok1(d->state == 1);
d->state++; d->state++;
...@@ -30,7 +30,7 @@ static struct io_op *timeout(struct io_conn *conn, struct data *d) ...@@ -30,7 +30,7 @@ static struct io_op *timeout(struct io_conn *conn, struct data *d)
return io_close(conn, d); return io_close(conn, d);
} }
static struct io_op *start_ok(struct io_conn *conn, struct data *d) static struct io_plan *start_ok(struct io_conn *conn, struct data *d)
{ {
ok1(d->state == 0); ok1(d->state == 0);
d->state++; d->state++;
......
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