aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/clock.h2
-rw-r--r--src/core/endpt.c30
-rw-r--r--src/core/platform.h4
3 files changed, 26 insertions, 10 deletions
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.