]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-18-errno.c
io: fix maybe-uninitialized warning in test (-O2)
[ccan] / ccan / io / test / run-18-errno.c
index 985a32297187a303cb5f92a0b9fe99635ffbde78..1bee7682bba94ea26c6b5e885e29bae6e8d50f98 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64018"
+#else
 #define PORT "65018"
 #endif
 
@@ -22,23 +24,27 @@ static void finish_EBADF(struct io_conn *conn, int *state)
        ok1(errno == EBADF);
        ok1(*state == 3);
        (*state)++;
-       io_break(state + 1, io_close());
+       io_break(state + 1);
 }
 
-static void init_conn(int fd, int *state)
+static struct io_plan *init_conn(struct io_conn *conn, int *state)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        if (*state == 0) {
                (*state)++;
                errno = 100;
-               io_set_finish(io_new_conn(fd, io_close()), finish_100, state);
+               io_set_finish(conn, finish_100, state);
+               return io_close(conn);
        } else {
                ok1(*state == 2);
                (*state)++;
-               close(fd);
+               close(io_conn_fd(conn));
                errno = 0;
-               io_set_finish(io_new_conn(fd, io_read(state, 0,
-                                                     io_close_cb, NULL)),
-                             finish_EBADF, state);
+               io_set_finish(conn, finish_EBADF, state);
+
+               return io_read(conn, state, 1, io_close_cb, NULL);
        }
 }
 
@@ -85,7 +91,7 @@ int main(void)
        plan_tests(12);
        fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
-       l = io_new_listener(fd, init_conn, &state);
+       l = io_new_listener(NULL, fd, init_conn, &state);
        ok1(l);
        fflush(stdout);
        if (!fork()) {
@@ -108,7 +114,7 @@ int main(void)
                exit(0);
        }
        freeaddrinfo(addrinfo);
-       ok1(io_loop() == &state + 1);
+       ok1(io_loop(NULL, NULL) == &state + 1);
        ok1(state == 4);
        io_close_listener(l);
        ok1(wait(&state));