This is a better description, since it's I/O we plan to do next.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
* };
*
* // 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.
- * static struct io_op *write_to_child(struct io_conn *c,
- * struct stdin_buffer *b);
- * static struct io_op *read_stdin(struct io_conn *c, struct stdin_buffer *b)
+ * static struct io_plan *write_to_child(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);
* b->len = sizeof(b->inbuf);
* 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);
* io_wake(b->writer, write_to_child, b);
* 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);
* io_wake(b->reader, read_stdin, b);
* return io_idle(c);
* }
*
- * static struct io_op *write_to_child(struct io_conn *conn,
- * struct stdin_buffer *b)
+ * static struct io_plan *write_to_child(struct io_conn *conn,
+ * struct stdin_buffer *b)
* {
* assert(conn == b->writer);
* if (!b->reader)
* return io_write(b->inbuf, b->len, io_next(conn, wake_reader, b));
* }
*
- * static struct io_op *start_writer(struct io_conn *conn,
- * struct stdin_buffer *b)
+ * static struct io_plan *start_writer(struct io_conn *conn,
+ * struct stdin_buffer *b)
* {
* assert(conn == b->writer);
* return io_idle(conn);
* }
*
* // This reads from the child and saves it into buffer.
- * static struct io_op *read_from_child(struct io_conn *conn,
- * struct buffer *b)
+ * static struct io_plan *read_from_child(struct io_conn *conn,
+ * struct buffer *b)
* {
* b->off += b->rlen;
*
bool listener;
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 (*finish)(struct io_conn *, void *arg);
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;
}
struct timer timer;
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;
};
bool add_conn(struct io_conn *c);
bool add_duplex(struct io_conn *c);
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_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 */
char reply_buffer[REPLY_SIZE];
};
-static struct io_op *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 *write_reply(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,
io_next(conn, write_reply, client));
}
/* 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++;
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,
io_next(conn, write_complete, client));
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);
}
-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));
}
char *request_buffer;
};
-static struct io_op *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 *write_reply(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);
return io_read(client->request_buffer, client->len,
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),
io_next(conn, read_body, client));
}
/* 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++;
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),
io_next(conn, write_complete, client));
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);
}
-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));
}
char buf[32];
};
-static struct io_op *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_writer(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);
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);
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);
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);
/* You read. */
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);
void *io_loop_return;
struct io_listener *io_new_listener_(int fd,
- struct io_op *(*start)(struct io_conn *,
- void *arg),
+ struct io_plan *(*start)(struct io_conn *,
+ void *arg),
void (*finish)(struct io_conn *, void *),
void *arg)
{
}
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 *arg)
{
}
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 *arg)
{
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)
}
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)
{
conn->fd.next = next;
}
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) {
conn->timeout = malloc(sizeof(*conn->timeout));
}
/* 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);
conn->u.write.buf = data;
conn->u.write.len = len;
- return to_ioop(WRITE);
+ return to_ioplan(WRITE);
}
/* 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);
conn->u.read.buf = data;
conn->u.read.len = len;
- return to_ioop(READ);
+ return to_ioplan(READ);
}
/* 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);
conn->u.readpart.buf = data;
conn->u.readpart.lenp = len;
- return to_ioop(READPART);
+ return to_ioplan(READPART);
}
/* 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);
conn->u.writepart.buf = data;
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,
- 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. */
assert(conn->state == IDLE);
conn->fd.next = next;
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))
backend_del_timeout(conn);
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;
bool finished;
if (finished)
return do_next(conn);
- return to_ioop(conn->state);
+ return to_ioplan(conn->state);
}
/* Useful next functions. */
/* 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. */
-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;
- return to_ioop(NEXT);
+ return to_ioplan(NEXT);
}
#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
- * really do return the result of an io-queueing method.
+ * A plan of what IO to do, when.
*/
-struct io_op;
+struct io_plan;
/**
* struct io_next - pointer to what we're going to do next.
*/
#define io_new_conn(fd, start, finish, arg) \
io_new_conn_((fd), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), (arg), \
struct io_conn *), \
(arg))
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 *arg);
*/
#define io_new_listener(fd, start, finish, arg) \
io_new_listener_((fd), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), \
struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), \
(arg), struct io_conn *), \
(arg))
struct io_listener *io_new_listener_(int fd,
- struct io_op *(*start)(struct io_conn *,
- void *arg),
+ struct io_plan *(*start)(struct io_conn *,
+ void *arg),
void (*finish)(struct io_conn *,
void *arg),
void *arg);
*
* 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.
*
* 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).
*
* 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).
*
* 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);
/**
* later call io_read/io_write etc. (or io_close) on it, in which case
* 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.
*/
#define io_timeout(conn, ts, next, arg) \
io_timeout_((conn), (ts), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), \
struct io_conn *), \
(arg))
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.
*/
#define io_duplex(conn, start, finish, arg) \
io_duplex_((conn), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(start), (arg), struct io_conn *), \
typesafe_cb_preargs(void, void *, (finish), (arg), \
struct io_conn *), \
(arg))
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 *arg);
*/
#define io_wake(conn, next, arg) \
io_wake_((conn), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), struct io_conn *), \
(arg))
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()
*
* 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.
*/
#define io_next(conn, next, arg) \
io_next_((conn), \
- typesafe_cb_preargs(struct io_op *, void *, \
+ typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), struct io_conn *), \
(arg))
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);
/* FIXME: io_recvfrom/io_sendto */
* It's common to 'return io_close(...)' from a @next function, but
* 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.
}
}
-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];
if (pfd->events)
#include <sys/wait.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);
(*state)++;
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);
d->state++;
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);
d->state++;
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);
d->state++;
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);
d->state++;
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);
d->state++;
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);
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;
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);
d->state++;
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);
d->state++;
char buf[32];
};
-static struct io_op *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_writer(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);
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);
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);
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);
/* You read. */
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);
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++;
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);
d->state++;
#include <stdio.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);
}
};
-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);
d->state++;
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);
d->state++;
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);
d->state++;