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
This commit is contained in:
Johan Danielsson
1997-08-30 19:34:30 +00:00
parent ea294cc756
commit 23c621c662

View File

@@ -212,6 +212,8 @@ clear_descr(struct descr *d)
d->s = -1; d->s = -1;
} }
#define TCP_TIMEOUT 4
static void static void
handle_tcp(struct descr *d, int index, int min_free) 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].s = s;
d[min_free].timeout = time(NULL) + 4; d[min_free].timeout = time(NULL) + TCP_TIMEOUT;
d[min_free].type = SOCK_STREAM; d[min_free].type = SOCK_STREAM;
return; return;
} }
@@ -308,7 +310,7 @@ handle_tcp(struct descr *d, int index, int min_free)
"<TITLE>404 Not found</TITLE>\r\n" "<TITLE>404 Not found</TITLE>\r\n"
"<H1>404 Not found</H1>\r\n" "<H1>404 Not found</H1>\r\n"
"That page doesn't exist, maybe you are looking for " "That page doesn't exist, maybe you are looking for "
"<a href=\"http://www.pdc.kth.se/heimdal\">Heimdal</a>?\r\n"; "<A HREF=\"http://www.pdc.kth.se/heimdal\">Heimdal</A>?\r\n";
write(d[index].s, msg, strlen(msg)); write(d[index].s, msg, strlen(msg));
free(data); free(data);
clear_descr(d + index); clear_descr(d + index);
@@ -345,6 +347,7 @@ loop(void)
int ndescr; int ndescr;
ndescr = init_sockets(&d); ndescr = init_sockets(&d);
while(exit_flag == 0){ while(exit_flag == 0){
struct timeval tmout;
struct fd_set fds; struct fd_set fds;
int min_free = -1; int min_free = -1;
int max_fd = 0; int max_fd = 0;
@@ -354,6 +357,13 @@ loop(void)
if(d[i].s >= 0){ if(d[i].s >= 0){
if(d[i].type == SOCK_STREAM && if(d[i].type == SOCK_STREAM &&
d[i].timeout && d[i].timeout < time(NULL)){ 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]); clear_descr(&d[i]);
continue; 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: case 0:
break; break;
case -1: case -1: