]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-17-homemade-io.c
ccan/io: flatten debug callchain.
[ccan] / ccan / io / test / run-17-homemade-io.c
index 08c081ec4238a1870637c39eb964b241d822c8c8..00fbf2233c59c9132c3f1c74a40e630429a64bf5 100644 (file)
@@ -23,7 +23,7 @@ static void finish_ok(struct io_conn *conn, struct packet *pkt)
        io_break(pkt, io_idle());
 }
 
-static bool do_read_packet(int fd, struct io_plan *plan)
+static int do_read_packet(int fd, struct io_plan *plan)
 {
        struct packet *pkt = plan->u.ptr_len.p;
        char *dest;
@@ -41,7 +41,7 @@ static bool do_read_packet(int fd, struct io_plan *plan)
                ok1(pkt->state == 2);
                pkt->state++;
                if (pkt->len == 0)
-                       return true;
+                       return 1;
                if (!pkt->contents && !(pkt->contents = malloc(pkt->len)))
                        goto fail;
                else {
@@ -63,9 +63,7 @@ static bool do_read_packet(int fd, struct io_plan *plan)
 
 fail:
        free(pkt->contents);
-       /* Override next function to close us. */
-       plan->next = io_close;
-       return true;
+       return -1;
 }
 
 static struct io_plan io_read_packet(struct packet *pkt,
@@ -83,7 +81,6 @@ static struct io_plan io_read_packet(struct packet *pkt,
        plan.next_arg = arg;
        plan.pollflag = POLLIN;
 
-       io_plan_debug(&plan);
        return plan;
 }
 
@@ -92,8 +89,8 @@ static void init_conn(int fd, struct packet *pkt)
        ok1(pkt->state == 0);
        pkt->state++;
 
-       if (!io_new_conn(fd, io_read_packet(pkt, io_close, pkt), finish_ok, pkt))
-               abort();
+       io_set_finish(io_new_conn(fd, io_read_packet(pkt, io_close_cb, pkt)),
+                     finish_ok, pkt);
 }
 
 static int make_listen_fd(const char *port, struct addrinfo **info)