summaryrefslogtreecommitdiff
path: root/src/core/endpt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-14 13:00:55 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-14 13:00:55 -0800
commitf4ce5a285167e7656037096f77f04ab80a010453 (patch)
tree48a9746e154872e4a01c9dee465aed716af278be /src/core/endpt.c
parentb639e4d3643b8245b77bc8707a3a864221fad195 (diff)
downloadnng-f4ce5a285167e7656037096f77f04ab80a010453.tar.gz
nng-f4ce5a285167e7656037096f77f04ab80a010453.tar.bz2
nng-f4ce5a285167e7656037096f77f04ab80a010453.zip
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.
Diffstat (limited to 'src/core/endpt.c')
-rw-r--r--src/core/endpt.c30
1 files changed, 23 insertions, 7 deletions
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);