Commit 733b09fa authored by Rusty Russell's avatar Rusty Russell

ccan/io: remove conn arg from io_plan constructors.

No longer needed.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 625bae8f
......@@ -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.
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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];
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
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