From 4735d7b69aaf0109b49a6a152b50099ad8400f96 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 13 Jul 2017 03:01:05 -0700 Subject: Windows implmentation of TCP is "working now". This is only lightly tested, and I expect that there remain some race conditions. Endpoint logic in particular needs work. --- src/transport/tcp/tcp.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/transport') diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index e60a1b1d..875eb71a 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -567,15 +567,28 @@ nni_tcp_ep_close(void *arg) { nni_tcp_ep *ep = arg; + nni_mtx_lock(&ep->mtx); + ep->closed = 1; nni_plat_tcp_ep_close(ep->tep); + nni_mtx_unlock(&ep->mtx); } static int nni_tcp_ep_bind(void *arg) { nni_tcp_ep *ep = arg; + int rv; + + nni_mtx_lock(&ep->mtx); + if (ep->closed) { + nni_mtx_unlock(&ep->mtx); + return (NNG_ECLOSED); + } - return (nni_plat_tcp_ep_listen(ep->tep)); + rv = nni_plat_tcp_ep_listen(ep->tep); + nni_mtx_unlock(&ep->mtx); + + return (rv); } static void @@ -638,6 +651,10 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio) int rv; nni_mtx_lock(&ep->mtx); + if (ep->closed) { + nni_aio_finish(aio, NNG_ECLOSED, 0); + nni_mtx_unlock(&ep->mtx); + } NNI_ASSERT(ep->user_aio == NULL); ep->user_aio = aio; @@ -659,6 +676,10 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio) int rv; nni_mtx_lock(&ep->mtx); + if (ep->closed) { + nni_aio_finish(aio, NNG_ECLOSED, 0); + nni_mtx_unlock(&ep->mtx); + } NNI_ASSERT(ep->user_aio == NULL); ep->user_aio = aio; -- cgit v1.2.3-70-g09d2