]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-07-break.c
ccan/io: generic init function for listening connections.
[ccan] / ccan / io / test / run-07-break.c
index 3dac4ecee2d9e6c0af85c07ce5eb3f1322cae67c..e8db388904638da90f913f9823bae60220337caa 100644 (file)
@@ -11,18 +11,18 @@ struct data {
        char buf[4];
 };
 
-static struct io_plan *plan_read(struct io_conn *conn, struct data *d)
+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)
+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)
@@ -31,6 +31,12 @@ static void finish_ok(struct io_conn *conn, struct data *d)
        d->state++;
 }
 
+static void init_conn(int fd, struct data *d)
+{
+       if (!io_new_conn(fd, start_break, finish_ok, d))
+               abort();
+}
+
 static int make_listen_fd(const char *port, struct addrinfo **info)
 {
        int fd, on = 1;
@@ -75,7 +81,7 @@ int main(void)
        d->state = 0;
        fd = make_listen_fd("65007", &addrinfo);
        ok1(fd >= 0);
-       l = io_new_listener(fd, start_break, finish_ok, d);
+       l = io_new_listener(fd, init_conn, d);
        ok1(l);
        fflush(stdout);
        if (!fork()) {