Adds a hardcoded connectionS idle timeout to pen (only for mainloop_select) see http://siag.nu/hypermail/pen/0464.html --- pen.c 2008-05-03 09:29:36.000000000 +0200 +++ pen.c-cnoSto 2009-02-07 16:34:00.000000000 +0100 @@ -2044,6 +2044,10 @@ loopflag = 1; + time_t lastcnSToloop = time(NULL); + int fdisset = 0; + unsigned int cnstoloop = 0; + if (debuglevel) debug("mainloop_select()"); while (loopflag) { int n; @@ -2150,33 +2154,53 @@ } /* check sockets from open connections */ + /* activate ConnectionS Timeout Loop only every ~ 120 secs */ + if ( (lastcnSToloop + 120) < time(NULL) ) { lastcnSToloop = time(NULL); cnstoloop = 1; } else { cnstoloop = 0; } for (i = 0; i < connections_max; i++) { + fdisset = 0; if (conns[i].downfd == -1) continue; if (FD_ISSET(conns[i].downfd, &w_read)) { + fdisset = 1; if (copy_up(i) < 0) { close_conn(i); continue; } } if (FD_ISSET(conns[i].upfd, &w_read)) { + fdisset = 1; if (copy_down(i) < 0) { close_conn(i); continue; } } if (FD_ISSET(conns[i].downfd, &w_write)) { + fdisset = 1; if (flush_down(i) < 0) { close_conn(i); continue; } } if (FD_ISSET(conns[i].upfd, &w_write)) { + fdisset = 1; if (flush_up(i) < 0) { close_conn(i); continue; } } - } + if (cnstoloop == 1 && fdisset == 0) { /* Only when flag is set && only when no "action" + happend within the last loop */ + /* lastcnSToloop is already "now" */ + int TOage = ((int)(lastcnSToloop-clients[conns[i].clt].last)); + if ( TOage > 75) { + debug("closing conn %d due to age ~ %ld (client %d ip %s server %d pendd %d pendu %d)", i, TOage, + conns[i].clt, inet_ntoa(clients[conns[i].clt].addr), conns[i].index, + conns[i].downn, conns[i].upn + ); + close_conn(i); + } + } + } + cnstoloop = 0; } }