X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-12-bidir.c;h=e79acb56db1ce2d68d605b3419e6aa813c4b938c;hb=1d415706a6e948fe6dcc3b5dab45812b297f77a1;hp=bddd7fbe9ed6a533d88998cb181e70a245279013;hpb=94dd4c2bddd0dc080ad5b85465fa3f45f486967a;p=ccan diff --git a/ccan/io/test/run-12-bidir.c b/ccan/io/test/run-12-bidir.c index bddd7fbe..e79acb56 100644 --- a/ccan/io/test/run-12-bidir.c +++ b/ccan/io/test/run-12-bidir.c @@ -6,14 +6,15 @@ #include #include -#ifndef PORT +#ifdef DEBUG_CONN +#define PORT "64012" +#else #define PORT "65012" #endif struct data { struct io_listener *l; int state; - int done; char buf[4]; char wbuf[32]; }; @@ -23,17 +24,27 @@ 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++; - d->done++; - if (d->done == 2) + 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++; @@ -42,8 +53,9 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d) memset(d->wbuf, 7, sizeof(d->wbuf)); io_set_finish(conn, finish_ok, d); - return io_duplex(io_read(conn, d->buf, sizeof(d->buf), rw_done, d), - io_write(conn, d->wbuf, sizeof(d->wbuf), rw_done, d)); + return io_duplex(conn, + 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) @@ -85,9 +97,8 @@ int main(void) int fd, status; /* This is how many tests you plan to run */ - plan_tests(10); + plan_tests(9); d->state = 0; - d->done = 0; fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); d->l = io_new_listener(NULL, fd, init_conn, d); @@ -121,7 +132,6 @@ int main(void) freeaddrinfo(addrinfo); ok1(io_loop(NULL, NULL) == NULL); ok1(d->state == 4); - ok1(d->done == 2); ok1(memcmp(d->buf, "hellothere", sizeof(d->buf)) == 0); free(d);