Commit cdf62dce authored by Rusty Russell's avatar Rusty Russell

io: io_never for events that should never happen.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 2a8b4826
......@@ -531,6 +531,16 @@ struct io_plan io_break_(void *ret, struct io_plan plan)
return plan;
}
static struct io_plan io_never_called(struct io_conn *conn, void *arg)
{
abort();
}
struct io_plan io_never(void)
{
return io_always_(io_never_called, NULL);
}
int io_conn_fd(const struct io_conn *conn)
{
return conn->fd.fd;
......
......@@ -490,6 +490,21 @@ bool io_is_idle(const struct io_conn *conn);
#define io_break(ret, plan) (io_plan_no_debug(), io_break_((ret), (plan)))
struct io_plan io_break_(void *ret, struct io_plan plan);
/**
* io_never - assert if callback is called.
*
* Sometimes you want to make it clear that a callback should never happen
* (eg. for io_break). This will assert() if called.
*
* Example:
* static struct io_plan break_out(struct io_conn *conn, void *unused)
* {
* // We won't ever return from io_break
* return io_break(conn, io_never());
* }
*/
struct io_plan io_never(void);
/* FIXME: io_recvfrom/io_sendto */
/**
......
......@@ -16,7 +16,7 @@ static void finish_ok(struct io_conn *conn, int *state)
ok1(*state == 1);
ok1(io_conn_fd(conn) == expected_fd);
(*state)++;
io_break(state + 1, io_idle());
io_break(state + 1, io_never());
}
static void init_conn(int fd, int *state)
......
......@@ -19,7 +19,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 1);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
......@@ -20,7 +20,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 1);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
......@@ -20,7 +20,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 1);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
......@@ -20,7 +20,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 1);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
......@@ -39,7 +39,7 @@ static void finish_idle(struct io_conn *conn, struct data *d)
{
ok1(d->state == 3);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static struct io_plan never(struct io_conn *conn, void *arg)
......
......@@ -38,7 +38,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 2);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
......@@ -20,7 +20,7 @@ static void finish_ok(struct io_conn *conn, struct packet *pkt)
{
ok1(pkt->state == 3);
pkt->state++;
io_break(pkt, io_idle());
io_break(pkt, io_never());
}
static int do_read_packet(int fd, struct io_plan *plan)
......
......@@ -20,7 +20,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 1);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static struct io_plan write_buf(struct io_conn *conn, struct data *d)
......
......@@ -95,7 +95,7 @@ static void finish_ok(struct io_conn *conn, struct data *d)
{
ok1(d->state == 2);
d->state++;
io_break(d, io_idle());
io_break(d, io_never());
}
static void init_conn(int fd, struct data *d)
......
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