From f4ce5a285167e7656037096f77f04ab80a010453 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 14 Jan 2017 13:00:55 -0800 Subject: Windows TCP now working. There are lots of changes here, mostly stuff we did in support of Windows TCP. However, there are some bugs that were fixed, and we added some new error codes, and generalized the handling of some failures during accept. Windows IPC (NamedPipes) is still missing. --- src/core/clock.h | 2 +- src/core/endpt.c | 30 +++++++++++++++++++++++------- src/core/platform.h | 4 ++-- 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src/core') diff --git a/src/core/clock.h b/src/core/clock.h index c46adfbe..3b607322 100644 --- a/src/core/clock.h +++ b/src/core/clock.h @@ -16,4 +16,4 @@ extern nni_time nni_clock(void); extern void nni_usleep(nni_duration usec); -#endif // CORE_CLOCK_H \ No newline at end of file +#endif // CORE_CLOCK_H diff --git a/src/core/endpt.c b/src/core/endpt.c index 554d9a36..c4673376 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -297,16 +297,32 @@ nni_listener(void *arg) if (((rv = nni_ep_accept(ep, &pipe)) == 0) && ((rv = nni_pipe_start(pipe)) == 0)) { + // Success! Loop around for the next one. continue; } - if (rv == NNG_ECLOSED) { + + switch (rv) { + case NNG_ECLOSED: + // This indicates the listening socket got closed. + // We just bail. + return; + + case NNG_ECONNABORTED: + case NNG_ECONNRESET: + // These are remote conditions, no cool down. + cooldown = 0; + break; + case NNG_ENOMEM: + // We're running low on memory, so its best to wait + // a whole second to give the system a chance to + // recover memory. + cooldown = 1000000; + break; + default: + // Other cases we sleep just a tiny bit to avoid + // burning the cpu (e.g. out of files). + cooldown = 1000; // 1 msec break; - } - cooldown = 1000; // 1 ms cooldown - if (rv == NNG_ENOMEM) { - // For out of memory, we need to give more - // time for the system to reclaim resources. - cooldown = 100000; // 100ms } cooldown += nni_clock(); nni_mtx_lock(mx); diff --git a/src/core/platform.h b/src/core/platform.h index bf8a52dc..8d19a7c8 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -170,7 +170,7 @@ extern int nni_plat_lookup_host(const char *, nni_sockaddr *, int); // nni_plat_tcp_init initializes the socket, for example it can // set underlying file descriptors to -1, etc. -extern void nni_plat_tcp_init(nni_plat_tcpsock *); +extern int nni_plat_tcp_init(nni_plat_tcpsock *); // nni_plat_tcp_fini just closes a TCP socket, and releases any related // resources. @@ -211,7 +211,7 @@ extern int nni_plat_tcp_recv(nni_plat_tcpsock *, nni_iov *, int); // nni_plat_ipc_init initializes the socket, for example it can // set underlying file descriptors to -1, etc. -extern void nni_plat_ipc_init(nni_plat_ipcsock *); +extern int nni_plat_ipc_init(nni_plat_ipcsock *); // nni_plat_ipc_fini just closes an IPC socket, and releases any related // resources. -- cgit v1.2.3-70-g09d2