]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-12-bidir.c
io: handle errors on listening file descriptors.
[ccan] / ccan / io / test / run-12-bidir.c
index 10f84295cb8650e6c8566289b9467fd9608561a6..77843ae7ba0bb2951d32c6d3e56b7d64d2916eed 100644 (file)
@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifdef DEBUG_CONN
-#define PORT "64012"
-#else
 #define PORT "65012"
-#endif
 
 struct data {
        struct io_listener *l;
@@ -24,17 +20,24 @@ static void finish_ok(struct io_conn *conn, struct data *d)
        d->state++;
 }
 
-static struct io_plan *rw_done(struct io_conn *conn, struct data *d)
+static struct io_plan *r_done(struct io_conn *conn, struct data *d)
 {
        d->state++;
-       return io_halfclose(conn);
+       if (d->state == 3)
+               return io_close(conn);
+       return io_wait(conn, NULL, io_never, NULL);
+}
+
+static struct io_plan *w_done(struct io_conn *conn, struct data *d)
+{
+       d->state++;
+       if (d->state == 3)
+               return io_close(conn);
+       return io_out_wait(conn, NULL, io_never, NULL);
 }
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
-#ifdef DEBUG_CONN
-       io_set_debug(conn, true);
-#endif
        ok1(d->state == 0);
        d->state++;
 
@@ -44,8 +47,8 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
        io_set_finish(conn, finish_ok, d);
 
        return io_duplex(conn,
-                        io_read(conn, d->buf, sizeof(d->buf), rw_done, d),
-                        io_write(conn, d->wbuf, sizeof(d->wbuf), rw_done, d));
+                        io_read(conn, d->buf, sizeof(d->buf), r_done, d),
+                        io_write(conn, d->wbuf, sizeof(d->wbuf), w_done, d));
 }
 
 static int make_listen_fd(const char *port, struct addrinfo **info)