From a1d543fc45dbd066020c8c15ea37421bdd49bc10 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 4 Jan 2017 11:03:54 -0800 Subject: Test for duplicate address listen, and fix in TCP for same. --- src/core/defs.h | 2 +- src/transport/tcp/tcp.c | 2 +- tests/trantest.h | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/defs.h b/src/core/defs.h index ed2e353f..92ebdb86 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -55,7 +55,7 @@ typedef struct { #define NNI_PUT16(ptr, u) \ do { \ (ptr)[0] = (uint8_t) (((uint16_t) (u)) >> 8); \ - (ptr)[0] = (uint8_t) ((uint16_t) (u)); \ + (ptr)[1] = (uint8_t) ((uint16_t) (u)); \ } \ while (0) diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 3fe31f9b..8cd91044 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -386,7 +386,7 @@ nni_tcp_ep_bind(void *arg) } baddr.s_un.s_in.sa_port = port; - if ((rv == nni_plat_tcp_listen(&ep->fd, &baddr)) != 0) { + if ((rv = nni_plat_tcp_listen(&ep->fd, &baddr)) != 0) { return (rv); } return (0); diff --git a/tests/trantest.h b/tests/trantest.h index a38db4b0..fb5392a5 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -64,6 +64,19 @@ trantest_conn_refused(trantest *tt) }) } +void +trantest_duplicate_listen(trantest *tt) +{ + Convey("Duplicate listen rejected", { + nng_endpoint *ep; + So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0); + So(ep != NULL); + ep = NULL; + So(nng_listen(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == NNG_EADDRINUSE); + So(ep == NULL); + }) +} + void trantest_test_all(const char *addr) { @@ -78,5 +91,6 @@ trantest_test_all(const char *addr) trantest_scheme(&tt); trantest_conn_refused(&tt); + trantest_duplicate_listen(&tt); }) -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2