]> git.ozlabs.org Git - ccan/commitdiff
io: io_never for events that should never happen.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 8 Apr 2014 09:33:52 +0000 (19:03 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Apr 2014 06:44:26 +0000 (16:14 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
12 files changed:
ccan/io/io.c
ccan/io/io.h
ccan/io/test/run-01-start-finish.c
ccan/io/test/run-02-read.c
ccan/io/test/run-03-readpartial.c
ccan/io/test/run-04-writepartial.c
ccan/io/test/run-05-write.c
ccan/io/test/run-06-idle.c
ccan/io/test/run-15-timeout.c
ccan/io/test/run-17-homemade-io.c
ccan/io/test/run-19-always.c
ccan/io/test/run-set_alloc.c

index 734cb3939636acbf0922362915c5c804bcc2cb97..90039e1e6960155a87862bbc1e86f9cbc987f35f 100644 (file)
@@ -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;
index ecbeb0b093bf6f0c43054b9a67e1233cff41bf66..478190f4d05b16def3f7eb481c2c8ecff334ee83 100644 (file)
@@ -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 */
 
 /**
index d8a24a52fe42b35e1ddf3a740b3d31d151f8165c..3ee659471847d73addc4c4e57b26e3eb6d2086c5 100644 (file)
@@ -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)
index c7a7eaf1c338704ad42cbcd3c6f7796377521134..439beb1f8a9ad6aaedab7ec1f8f4d72af2f527cc 100644 (file)
@@ -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)
index 7ecccc7412cd2aa3f2b5342614a695168e5e46d9..860792b7784bb3762f8204a6d9955b155477fb8c 100644 (file)
@@ -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)
index 8cfb2abeb16bb126c8db502ede3358fcf46d8ba2..5c1f5e015da50707999d77ee037b93853e8653bb 100644 (file)
@@ -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)
index 5319def8f2cc28c6921b2b611a2c99b013b1402d..2c3e1839991b3ef927ac24cd7b3ac5ad658a80fc 100644 (file)
@@ -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)
index 455b8608f1cae1723763154a5bb918d1b5a46a11..7ae16e9e96a3f8203c05d5d2778729c3573af290 100644 (file)
@@ -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)
index 6f92ec3a634848c0770fcd21016e56acfb082274..2aceb2b5b26badb86aed5daba74bf9e1f8742f54 100644 (file)
@@ -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)
index 65fe7415aba720aaaa83dbc9191459324ea9d28e..c5d82889021ce6430a47a2cdd81f8a5ae23d2135 100644 (file)
@@ -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)
index e6413fc916fec4434a8bc775a641fa0406a9c420..1805f79f6619b310834f191b36161e33aba741b0 100644 (file)
@@ -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)
index 61440056c8b8e5b37e9daf3ab3e764d24d57e8dc..8d20168992454f8ecbc9b2b64456737929a61955 100644 (file)
@@ -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)