From 23c621c6623304230def62b4891b7987c4a7390b Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sat, 30 Aug 1997 19:34:30 +0000 Subject: [PATCH] Add timeout to select, and log about expired tcp connections. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3298 ec53bebd-3082-4978-b11e-865c3cabbd6b --- kdc/connect.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kdc/connect.c b/kdc/connect.c index 433cde932..762932522 100644 --- a/kdc/connect.c +++ b/kdc/connect.c @@ -212,6 +212,8 @@ clear_descr(struct descr *d) d->s = -1; } +#define TCP_TIMEOUT 4 + static void handle_tcp(struct descr *d, int index, int min_free) { @@ -235,7 +237,7 @@ handle_tcp(struct descr *d, int index, int min_free) } d[min_free].s = s; - d[min_free].timeout = time(NULL) + 4; + d[min_free].timeout = time(NULL) + TCP_TIMEOUT; d[min_free].type = SOCK_STREAM; return; } @@ -308,7 +310,7 @@ handle_tcp(struct descr *d, int index, int min_free) "404 Not found\r\n" "

404 Not found

\r\n" "That page doesn't exist, maybe you are looking for " - "Heimdal?\r\n"; + "Heimdal?\r\n"; write(d[index].s, msg, strlen(msg)); free(data); clear_descr(d + index); @@ -345,6 +347,7 @@ loop(void) int ndescr; ndescr = init_sockets(&d); while(exit_flag == 0){ + struct timeval tmout; struct fd_set fds; int min_free = -1; int max_fd = 0; @@ -354,6 +357,13 @@ loop(void) if(d[i].s >= 0){ if(d[i].type == SOCK_STREAM && d[i].timeout && d[i].timeout < time(NULL)){ + struct sockaddr sa; + size_t salen = sizeof(sa); + char addr[32]; + getpeername(d[i].s, &sa, &salen); + addr_to_string(&sa, salen, addr, sizeof(addr)); + kdc_log(1, "TCP-connection from %s expired after %u bytes", + addr, d[i].len); clear_descr(&d[i]); continue; } @@ -378,7 +388,9 @@ loop(void) } } - switch(select(max_fd + 1, &fds, 0, 0, 0)){ + tmout.tv_sec = TCP_TIMEOUT; + tmout.tv_usec = 0; + switch(select(max_fd + 1, &fds, 0, 0, &tmout)){ case 0: break; case -1: