summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrofl0r <rofl0r@users.noreply.github.com>2020-07-15 09:59:25 +0100
committerrofl0r <rofl0r@users.noreply.github.com>2020-07-15 09:59:25 +0100
commit0b9a74c29036f9215b2b97a301b7b25933054302 (patch)
tree482729d70d7dca8d538d2fc1062d05d9a3e0eaa8
parent25e2cc330c5f6b403d91a316304f92bae0047227 (diff)
enforce socket timeout on new sockets via setsockopt()
the timeout option set by the config file wasn't respected at all so it could happen that connections became stale and were never released, which eventually caused tinyproxy to hit the limit of open connections and never accepting new ones. addresses #274
-rw-r--r--src/reqs.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/reqs.c b/src/reqs.c
index 041fb03..859ac6b 100644
--- a/src/reqs.c
+++ b/src/reqs.c
@@ -1539,6 +1539,7 @@ void handle_connection (int fd, union sockaddr_union* addr)
ssize_t i;
struct conn_s *connptr;
struct request_s *request = NULL;
+ struct timeval tv;
hashmap_t hashofheaders = NULL;
char sock_ipaddr[IP_LENGTH];
@@ -1561,6 +1562,13 @@ void handle_connection (int fd, union sockaddr_union* addr)
return;
}
+ tv.tv_usec = 0;
+ tv.tv_sec = config->idletimeout;
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*) &tv, sizeof(tv));
+ tv.tv_usec = 0;
+ tv.tv_sec = config->idletimeout;
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));
+
if (connection_loops (addr)) {
log_message (LOG_CONN,
"Prevented endless loop (file descriptor %d): %s",