From 7eb7471b35dd0e5b9e2da0668376af5b218264e6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 4 Jan 2017 12:47:26 -0800 Subject: TCP listen and accept test. There is an occasional use-after-free bug we need to fix still. --- src/platform/posix/posix_net.c | 2 +- src/transport/tcp/tcp.c | 2 +- tests/trantest.h | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/platform/posix/posix_net.c b/src/platform/posix/posix_net.c index 2fdab245..c7c5ce82 100644 --- a/src/platform/posix/posix_net.c +++ b/src/platform/posix/posix_net.c @@ -137,7 +137,6 @@ nni_plat_tcp_send(nni_plat_tcpsock *s, nni_iov *iovs, int cnt) if (rv > resid) { nni_panic("writev says it wrote too much!"); } - resid -= rv; while (rv) { if (iov[i].iov_len <= rv) { @@ -366,6 +365,7 @@ nni_plat_tcp_accept(nni_plat_tcpsock *s, nni_plat_tcpsock *server) } nni_plat_tcp_setopts(fd); + s->fd = fd; return (0); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 8cd91044..00d9a2f3 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -401,7 +401,7 @@ nni_tcp_ep_accept(void *arg, void **pipep) int rv; - if ((pipe = NNI_ALLOC_STRUCT(pipe)) != NULL) { + if ((pipe = NNI_ALLOC_STRUCT(pipe)) == NULL) { return (NNG_ENOMEM); } pipe->proto = ep->proto; diff --git a/tests/trantest.h b/tests/trantest.h index fb5392a5..3bc47e8d 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -77,6 +77,19 @@ trantest_duplicate_listen(trantest *tt) }) } +void +trantest_listen_accept(trantest *tt) +{ + Convey("Listen and accept" ,{ + nng_endpoint *ep; + So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); + So(ep != NULL); + + So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); + So(ep != NULL); + }) +} + void trantest_test_all(const char *addr) { @@ -92,5 +105,6 @@ trantest_test_all(const char *addr) trantest_scheme(&tt); trantest_conn_refused(&tt); trantest_duplicate_listen(&tt); + trantest_listen_accept(&tt); }) } -- cgit v1.2.3-70-g09d2