From 733b09fa8b6083949ff62795e54851aa282d510c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 14 Oct 2013 21:28:35 +1030 Subject: [PATCH] ccan/io: remove conn arg from io_plan constructors. No longer needed. Signed-off-by: Rusty Russell --- ccan/io/_info | 13 +++++----- ccan/io/io.c | 13 +++++----- ccan/io/io.h | 39 ++++++++++++------------------ ccan/io/test/run-01-start-finish.c | 2 +- ccan/io/test/run-02-read.c | 4 +-- ccan/io/test/run-03-readpartial.c | 4 +-- ccan/io/test/run-04-writepartial.c | 4 +-- ccan/io/test/run-05-write.c | 4 +-- ccan/io/test/run-06-idle.c | 6 ++--- ccan/io/test/run-07-break.c | 4 +-- ccan/io/test/run-10-many.c | 12 ++++----- ccan/io/test/run-12-bidir.c | 4 +-- ccan/io/test/run-13-all-idle.c | 2 +- ccan/io/test/run-15-timeout.c | 4 +-- 14 files changed, 52 insertions(+), 63 deletions(-) diff --git a/ccan/io/_info b/ccan/io/_info index e7dfe9da..150b93e5 100644 --- a/ccan/io/_info +++ b/ccan/io/_info @@ -40,14 +40,14 @@ * { * assert(c == b->reader); * b->len = sizeof(b->inbuf); - * return io_read_partial(c, b->inbuf, &b->len, wake_writer, b); + * return io_read_partial(b->inbuf, &b->len, wake_writer, 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); - * return io_idle(c); + * return io_idle(); * } * * static void reader_exit(struct io_conn *c, struct stdin_buffer *b) @@ -61,7 +61,7 @@ * { * assert(c == b->writer); * io_wake(b->reader, read_stdin, b); - * return io_idle(c); + * return io_idle(); * } * * static struct io_plan write_to_child(struct io_conn *conn, @@ -70,14 +70,14 @@ * assert(conn == b->writer); * if (!b->reader) * return io_close(conn, NULL); - * return io_write(conn, b->inbuf, b->len, wake_reader, b); + * return io_write(b->inbuf, b->len, wake_reader, b); * } * * static struct io_plan start_writer(struct io_conn *conn, * struct stdin_buffer *b) * { * assert(conn == b->writer); - * return io_idle(conn); + * return io_idle(); * } * * static void fail_child_write(struct io_conn *conn, struct stdin_buffer *b) @@ -103,8 +103,7 @@ * } * * b->rlen = b->max - b->off; - * return io_read_partial(conn, b->buf + b->off, &b->rlen, - * read_from_child, b); + * return io_read_partial(b->buf + b->off, &b->rlen, read_from_child, b); * } * * // Feed a program our stdin, gather its stdout, print that at end. diff --git a/ccan/io/io.c b/ccan/io/io.c index fe9fed4f..bad06939 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -129,7 +129,7 @@ static enum io_result do_write(struct io_conn *conn) } /* Queue some data to be written. */ -struct io_plan io_write_(struct io_conn *conn, const void *data, size_t len, +struct io_plan io_write_(const void *data, size_t len, struct io_plan (*cb)(struct io_conn *, void *), void *arg) { @@ -160,7 +160,7 @@ static enum io_result do_read(struct io_conn *conn) } /* Queue a request to read into a buffer. */ -struct io_plan io_read_(struct io_conn *conn, void *data, size_t len, +struct io_plan io_read_(void *data, size_t len, struct io_plan (*cb)(struct io_conn *, void *), void *arg) { @@ -187,7 +187,7 @@ static enum io_result do_read_partial(struct io_conn *conn) } /* Queue a partial request to read into a buffer. */ -struct io_plan io_read_partial_(struct io_conn *conn, void *data, size_t *len, +struct io_plan io_read_partial_(void *data, size_t *len, struct io_plan (*cb)(struct io_conn *, void *), void *arg) { @@ -215,8 +215,7 @@ static enum io_result do_write_partial(struct io_conn *conn) } /* Queue a partial write request. */ -struct io_plan io_write_partial_(struct io_conn *conn, - const void *data, size_t *len, +struct io_plan io_write_partial_(const void *data, size_t *len, struct io_plan (*cb)(struct io_conn*, void *), void *arg) { @@ -233,7 +232,7 @@ struct io_plan io_write_partial_(struct io_conn *conn, return plan; } -struct io_plan io_idle(struct io_conn *conn) +struct io_plan io_idle(void) { struct io_plan plan; @@ -293,7 +292,7 @@ struct io_plan io_close(struct io_conn *conn, void *arg) } /* Exit the loop, returning this (non-NULL) arg. */ -struct io_plan io_break_(struct io_conn *conn, void *ret, +struct io_plan io_break_(void *ret, struct io_plan (*fn)(struct io_conn *, void *), void *arg) { diff --git a/ccan/io/io.h b/ccan/io/io.h index a027fe71..e48f15b5 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -127,7 +127,6 @@ void io_close_listener(struct io_listener *listener); /** * io_write - queue data to be written. - * @conn: the current connection. * @data: the data buffer. * @len: the length to write. * @cb: function to call once it's done. @@ -139,18 +138,17 @@ void io_close_listener(struct io_listener *listener); * * Note that the I/O may actually be done immediately. */ -#define io_write(conn, data, len, cb, arg) \ - io_write_((conn), (data), (len), \ +#define io_write(data, len, cb, arg) \ + io_write_((data), (len), \ typesafe_cb_preargs(struct io_plan, void *, \ (cb), (arg), struct io_conn *), \ (arg)) -struct io_plan io_write_(struct io_conn *conn, const void *data, size_t len, +struct io_plan io_write_(const void *data, size_t len, struct io_plan (*cb)(struct io_conn *, void *), void *arg); /** * io_read - queue buffer to be read. - * @conn: the current connection. * @data: the data buffer. * @len: the length to read. * @cb: function to call once it's done. @@ -162,19 +160,18 @@ struct io_plan io_write_(struct io_conn *conn, const void *data, size_t len, * * Note that the I/O may actually be done immediately. */ -#define io_read(conn, data, len, cb, arg) \ - io_read_((conn), (data), (len), \ +#define io_read(data, len, cb, arg) \ + io_read_((data), (len), \ typesafe_cb_preargs(struct io_plan, void *, \ (cb), (arg), struct io_conn *), \ (arg)) -struct io_plan io_read_(struct io_conn *conn, void *data, size_t len, +struct io_plan io_read_(void *data, size_t len, struct io_plan (*cb)(struct io_conn *, void *), void *arg); /** * io_read_partial - queue buffer to be read (partial OK). - * @conn: the current connection. * @data: the data buffer. * @len: the maximum length to read, set to the length actually read. * @cb: function to call once it's done. @@ -186,18 +183,17 @@ struct io_plan io_read_(struct io_conn *conn, void *data, size_t len, * * Note that the I/O may actually be done immediately. */ -#define io_read_partial(conn, data, len, cb, arg) \ - io_read_partial_((conn), (data), (len), \ +#define io_read_partial(data, len, cb, arg) \ + io_read_partial_((data), (len), \ typesafe_cb_preargs(struct io_plan, void *, \ (cb), (arg), struct io_conn *), \ (arg)) -struct io_plan io_read_partial_(struct io_conn *conn, void *data, size_t *len, +struct io_plan io_read_partial_(void *data, size_t *len, struct io_plan (*cb)(struct io_conn *, void *), void *arg); /** * io_write_partial - queue data to be written (partial OK). - * @conn: the current connection. * @data: the data buffer. * @len: the maximum length to write, set to the length actually written. * @cb: function to call once it's done. @@ -209,26 +205,24 @@ struct io_plan io_read_partial_(struct io_conn *conn, void *data, size_t *len, * * Note that the I/O may actually be done immediately. */ -#define io_write_partial(conn, data, len, cb, arg) \ - io_write_partial_((conn), (data), (len), \ +#define io_write_partial(data, len, cb, arg) \ + io_write_partial_((data), (len), \ typesafe_cb_preargs(struct io_plan, void *, \ (cb), (arg), struct io_conn *), \ (arg)) -struct io_plan io_write_partial_(struct io_conn *conn, - const void *data, size_t *len, +struct io_plan io_write_partial_(const void *data, size_t *len, struct io_plan (*cb)(struct io_conn *, void*), void *arg); /** * io_idle - explicitly note that this connection will do nothing. - * @conn: the current connection. * * This indicates the connection is idle: some other function will * later call io_read/io_write etc. (or io_close) on it, in which case * it will do that. */ -struct io_plan io_idle(struct io_conn *conn); +struct io_plan io_idle(void); /** * io_timeout - set timeout function if the callback doesn't fire. @@ -299,7 +293,6 @@ void io_wake_(struct io_conn *conn, /** * io_break - return from io_loop() - * @conn: the current connection. * @ret: non-NULL value to return from io_loop(). * @cb: function to call once on return * @arg: @cb argument @@ -310,12 +303,12 @@ void io_wake_(struct io_conn *conn, * * If io_loop() is called again, then @cb will be called. */ -#define io_break(conn, ret, fn, arg) \ - io_break_((conn), (ret), \ +#define io_break(ret, fn, arg) \ + io_break_((ret), \ typesafe_cb_preargs(struct io_plan, void *, \ (fn), (arg), struct io_conn *), \ (arg)) -struct io_plan io_break_(struct io_conn *conn, void *ret, +struct io_plan io_break_(void *ret, struct io_plan (*fn)(struct io_conn *, void *), void *arg); diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index 7c6ae415..b879a2c8 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -17,7 +17,7 @@ static void finish_ok(struct io_conn *conn, int *state) { ok1(*state == 1); (*state)++; - io_break(conn, state + 1, NULL, NULL); + io_break(state + 1, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-02-read.c b/ccan/io/test/run-02-read.c index 8b96f029..e5a6142c 100644 --- a/ccan/io/test/run-02-read.c +++ b/ccan/io/test/run-02-read.c @@ -15,14 +15,14 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 0); d->state++; - return io_read(conn, d->buf, sizeof(d->buf), io_close, d); + return io_read(d->buf, sizeof(d->buf), io_close, d); } static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-03-readpartial.c b/ccan/io/test/run-03-readpartial.c index e6e33e3d..0d5f636e 100644 --- a/ccan/io/test/run-03-readpartial.c +++ b/ccan/io/test/run-03-readpartial.c @@ -17,14 +17,14 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) ok1(d->state == 0); d->state++; d->bytes = sizeof(d->buf); - return io_read_partial(conn, d->buf, &d->bytes, io_close, d); + return io_read_partial(d->buf, &d->bytes, io_close, d); } static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-04-writepartial.c b/ccan/io/test/run-04-writepartial.c index d4e33c96..5a5b2506 100644 --- a/ccan/io/test/run-04-writepartial.c +++ b/ccan/io/test/run-04-writepartial.c @@ -16,14 +16,14 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 0); d->state++; - return io_write_partial(conn, d->buf, &d->bytes, io_close, d); + return io_write_partial(d->buf, &d->bytes, io_close, d); } static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-05-write.c b/ccan/io/test/run-05-write.c index ad6760e4..07cc3e0d 100644 --- a/ccan/io/test/run-05-write.c +++ b/ccan/io/test/run-05-write.c @@ -16,14 +16,14 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 0); d->state++; - return io_write(conn, d->buf, d->bytes, io_close, d); + return io_write(d->buf, d->bytes, io_close, d); } static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-06-idle.c b/ccan/io/test/run-06-idle.c index 19d0f8b1..c5fab50b 100644 --- a/ccan/io/test/run-06-idle.c +++ b/ccan/io/test/run-06-idle.c @@ -20,7 +20,7 @@ static struct io_plan plan_read(struct io_conn *conn, struct data *d) { ok1(d->state == 2 || d->state == 3); d->state++; - return io_read(conn, d->buf, sizeof(d->buf), io_close, d); + return io_read(d->buf, sizeof(d->buf), io_close, d); } static struct io_plan start_waker(struct io_conn *conn, struct data *d) @@ -51,14 +51,14 @@ static struct io_plan start_idle(struct io_conn *conn, struct data *d) ok1(fd >= 0); ok1(io_new_conn(fd, start_waker, finish_waker, d)); - return io_idle(conn); + return io_idle(); } static void finish_idle(struct io_conn *conn, struct data *d) { ok1(d->state == 4); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-07-break.c b/ccan/io/test/run-07-break.c index 5bc0e8c6..d7896591 100644 --- a/ccan/io/test/run-07-break.c +++ b/ccan/io/test/run-07-break.c @@ -15,14 +15,14 @@ static struct io_plan plan_read(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - return io_read(conn, d->buf, sizeof(d->buf), io_close, d); + return io_read(d->buf, sizeof(d->buf), io_close, d); } static struct io_plan start_break(struct io_conn *conn, struct data *d) { ok1(d->state == 0); d->state++; - return io_break(conn, d, plan_read, d); + return io_break(d, plan_read, d); } static void finish_ok(struct io_conn *conn, struct data *d) diff --git a/ccan/io/test/run-10-many.c b/ccan/io/test/run-10-many.c index 91b335e1..95a716e2 100644 --- a/ccan/io/test/run-10-many.c +++ b/ccan/io/test/run-10-many.c @@ -22,16 +22,14 @@ static struct io_plan plan_read(struct io_conn *conn, struct buffer *buf) { assert(conn == buf->reader); - return io_read(conn, &buf->buf, sizeof(buf->buf), - poke_writer, buf); + return io_read(&buf->buf, sizeof(buf->buf), poke_writer, buf); } static struct io_plan plan_write(struct io_conn *conn, struct buffer *buf) { assert(conn == buf->writer); - return io_write(conn, &buf->buf, sizeof(buf->buf), - poke_reader, buf); + return io_write(&buf->buf, sizeof(buf->buf), poke_reader, buf); } static struct io_plan poke_writer(struct io_conn *conn, struct buffer *buf) @@ -45,7 +43,7 @@ static struct io_plan poke_writer(struct io_conn *conn, struct buffer *buf) io_wake(buf->writer, plan_write, buf); /* I'll wait until you wake me. */ - return io_idle(conn); + return io_idle(); } static struct io_plan poke_reader(struct io_conn *conn, struct buffer *buf) @@ -58,7 +56,7 @@ static struct io_plan poke_reader(struct io_conn *conn, struct buffer *buf) return io_close(conn, NULL); /* I'll wait until you tell me to write. */ - return io_idle(conn); + return io_idle(); } static struct io_plan reader(struct io_conn *conn, struct buffer *buf) @@ -66,7 +64,7 @@ static struct io_plan reader(struct io_conn *conn, struct buffer *buf) assert(conn == buf->reader); /* Wait for writer to tell us to read. */ - return io_idle(conn); + return io_idle(); } static struct buffer buf[NUM]; diff --git a/ccan/io/test/run-12-bidir.c b/ccan/io/test/run-12-bidir.c index 0cafb4f2..5b39f38d 100644 --- a/ccan/io/test/run-12-bidir.c +++ b/ccan/io/test/run-12-bidir.c @@ -21,7 +21,7 @@ static void finish_ok(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(conn, d->wbuf, sizeof(d->wbuf), io_close, d); + return io_write(d->wbuf, sizeof(d->wbuf), io_close, d); } static struct io_plan start_ok(struct io_conn *conn, struct data *d) @@ -33,7 +33,7 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) memset(d->wbuf, 7, sizeof(d->wbuf)); ok1(io_duplex(conn, write_out, finish_ok, d)); - return io_read(conn, d->buf, sizeof(d->buf), io_close, d); + return io_read(d->buf, sizeof(d->buf), io_close, d); } static int make_listen_fd(const char *port, struct addrinfo **info) diff --git a/ccan/io/test/run-13-all-idle.c b/ccan/io/test/run-13-all-idle.c index 178b68a8..f83fb31e 100644 --- a/ccan/io/test/run-13-all-idle.c +++ b/ccan/io/test/run-13-all-idle.c @@ -9,7 +9,7 @@ static struct io_plan start(struct io_conn *conn, void *unused) { - return io_idle(conn); + return io_idle(); } int main(void) diff --git a/ccan/io/test/run-15-timeout.c b/ccan/io/test/run-15-timeout.c index 5e94b8c0..2f5c60ac 100644 --- a/ccan/io/test/run-15-timeout.c +++ b/ccan/io/test/run-15-timeout.c @@ -35,14 +35,14 @@ static struct io_plan start_ok(struct io_conn *conn, struct data *d) ok1(d->state == 0); d->state++; io_timeout(conn, time_from_usec(d->timeout_usec), timeout, d); - return io_read(conn, d->buf, sizeof(d->buf), no_timeout, d); + return io_read(d->buf, sizeof(d->buf), no_timeout, d); } static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 2); d->state++; - io_break(conn, d, NULL, NULL); + io_break(d, NULL, NULL); } static int make_listen_fd(const char *port, struct addrinfo **info) -- 2.39.2