Skip to content

Commit

Permalink
use a common FAILURE_TIMEOUT value for both resource exhaustion scena…
Browse files Browse the repository at this point in the history
…rios

can be overridden by user by supplying CPPFLAGS=-DFAILURE_TIMEOUT=xxx
to config.mak / make invocation.
  • Loading branch information
rofl0r committed Nov 29, 2021
1 parent 42143b1 commit 9d463f4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sockssrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9d463f4

Please sign in to comment.