From 9d463f4297794f3e8a29488af087fe93ddd1a60c Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 29 Nov 2021 09:43:47 +0000 Subject: [PATCH] use a common FAILURE_TIMEOUT value for both resource exhaustion scenarios can be overridden by user by supplying CPPFLAGS=-DFAILURE_TIMEOUT=xxx to config.mak / make invocation. --- sockssrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sockssrv.c b/sockssrv.c index c81347b..2821a3e 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -36,6 +36,12 @@ #include "server.h" #include "sblist.h" +/* timeout in microseconds on resource exhaustion to prevent excessive + cpu usage. */ +#ifndef FAILURE_TIMEOUT +#define FAILURE_TIMEOUT 64 +#endif + #ifndef MAX #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif @@ -442,7 +448,7 @@ int main(int argc, char** argv) { if(server_waitclient(&s, &c)) { dolog("failed to accept connection\n"); free(curr); - usleep(1000); + usleep(FAILURE_TIMEOUT); continue; } curr->client = c; @@ -451,7 +457,7 @@ int main(int argc, char** argv) { free(curr); oom: dolog("rejecting connection due to OOM\n"); - usleep(16); /* prevent 100% CPU usage in OOM situation */ + usleep(FAILURE_TIMEOUT); /* prevent 100% CPU usage in OOM situation */ continue; } pthread_attr_t *a = 0, attr; -- 2.11.4.GIT