X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-16-duplex-test.c;h=8631be4519f58a0e0603da35e1d539b34af1dcd8;hp=e31c5c5bad95ae0117b53740cc63d17c1dbc4298;hb=d8ecdc8021b532fe76f001290fcd79c4fb9e1323;hpb=cdffdf5d61f8330cfc3467e73a84876eb3928e9b diff --git a/ccan/io/test/run-16-duplex-test.c b/ccan/io/test/run-16-duplex-test.c index e31c5c5b..8631be45 100644 --- a/ccan/io/test/run-16-duplex-test.c +++ b/ccan/io/test/run-16-duplex-test.c @@ -8,14 +8,14 @@ #include #include -#if 0 -#ifndef PORT +#ifdef DEBUG_CONN +#define PORT "64016" +#else #define PORT "65016" #endif struct data { struct io_listener *l; - struct io_conn *writer; int state; char buf[4]; char wbuf[32]; @@ -26,35 +26,29 @@ static void finish_ok(struct io_conn *conn, struct data *d) d->state++; } -static struct io_plan write_done(struct io_conn *conn, struct data *d) +static struct io_plan *io_done(struct io_conn *conn, struct data *d) { d->state++; - return io_wait(d, io_close_cb, NULL); + return io_halfclose(conn); } -static struct io_plan read_done(struct io_conn *conn, struct data *d) +static struct io_plan *init_conn(struct io_conn *conn, struct data *d) { - d->state++; - io_close_other(d->writer); - return io_close(); -} - -static void init_conn(int fd, struct data *d) -{ - struct io_conn *conn; - +#ifdef DEBUG_CONN + io_set_debug(conn, true); +#endif ok1(d->state == 0); d->state++; memset(d->wbuf, 7, sizeof(d->wbuf)); - conn = io_new_conn(fd, io_read(d->buf, sizeof(d->buf), read_done, d)); io_set_finish(conn, finish_ok, d); - d->writer = io_duplex(conn, io_write(d->wbuf, sizeof(d->wbuf), write_done, d)); - ok1(d->writer); - io_set_finish(d->writer, finish_ok, d); io_close_listener(d->l); + + return io_duplex(conn, + io_read(conn, d->buf, sizeof(d->buf), io_done, d), + io_write(conn, d->wbuf, sizeof(d->wbuf), io_done, d)); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -96,11 +90,11 @@ int main(void) int fd, status; /* This is how many tests you plan to run */ - plan_tests(10); + plan_tests(9); d->state = 0; fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); - d->l = io_new_listener(fd, init_conn, d); + d->l = io_new_listener(NULL, fd, init_conn, d); ok1(d->l); fflush(stdout); if (!fork()) { @@ -129,8 +123,8 @@ int main(void) exit(0); } freeaddrinfo(addrinfo); - ok1(io_loop() == NULL); - ok1(d->state == 5); + ok1(io_loop(NULL, NULL) == NULL); + ok1(d->state == 4); ok1(memcmp(d->buf, "hellothere", sizeof(d->buf)) == 0); free(d); @@ -141,9 +135,3 @@ int main(void) /* This exits depending on whether all tests passed */ return exit_status(); } -#else -int main(void) -{ - return 0; -} -#endif