Browse code

- tcp connection timeouts are checked at most one time per second - ticks comparisons are uint overflow safe

Andrei Pelinescu-Onciul authored on 03/02/2006 15:34:57
Showing 1 changed files
... ...
@@ -63,6 +63,7 @@
63 63
  *              poll loop  (#ifdef) (andrei)
64 64
  *              process all children requests, before attempting to send
65 65
  *              them new stuff (fixes some deadlocks) (andrei)
66
+ *  2006-02-03  timers are run only once per s (andrei)
66 67
  */
67 68
 
68 69
 
... ...
@@ -121,7 +122,7 @@
121 121
 #include <fcntl.h> /* must be included after io_wait.h if SIGIO_RT is used */
122 122
 
123 123
 #define MAX_TCP_CHILDREN 100
124
-
124
+#define TCP_LISTEN_BACKLOG 1024
125 125
 /* #define SEND_FD_QUEUE */ /* queue send fd request, instead of sending 
126 126
 							   them immediately */
127 127
 #ifdef SEND_FD_QUEUE
... ...
@@ -921,7 +922,7 @@ int tcp_init(struct socket_info* sock_info)
921 921
 				strerror(errno));
922 922
 		goto error;
923 923
 	}
924
-	if (listen(sock_info->socket, 1024)==-1){
924
+	if (listen(sock_info->socket, TCP_LISTEN_BACKLOG)==-1){
925 925
 		LOG(L_ERR, "ERROR: tcp_init: listen(%x, %p, %d) on %s: %s\n",
926 926
 				sock_info->socket, &addr->s, 
927 927
 				(unsigned)sockaddru_len(*addr),
... ...
@@ -1566,19 +1567,22 @@ error:
1566 1566
  * the same except for io_watch_del..*/
1567 1567
 static inline void tcpconn_timeout(int force)
1568 1568
 {
1569
+	static int prev_ticks=0;
1569 1570
 	struct tcp_connection *c, *next;
1570
-	int ticks;
1571
+	unsigned int ticks;
1571 1572
 	unsigned h;
1572 1573
 	int fd;
1573 1574
 	
1574 1575
 	
1575 1576
 	ticks=get_ticks();
1577
+	if ((ticks==prev_ticks) && !force) return;
1578
+	prev_ticks=ticks;
1576 1579
 	TCPCONN_LOCK; /* fixme: we can lock only on delete IMO */
1577 1580
 	for(h=0; h<TCP_ID_HASH_SIZE; h++){
1578 1581
 		c=tcpconn_id_hash[h];
1579 1582
 		while(c){
1580 1583
 			next=c->id_next;
1581
-			if (force ||((c->refcnt==0) && (ticks>c->timeout))) {
1584
+			if (force ||((c->refcnt==0) && ((int)(ticks-c->timeout)>=0))){
1582 1585
 				if (!force)
1583 1586
 					DBG("tcpconn_timeout: timeout for hash=%d - %p"
1584 1587
 							" (%d > %d)\n", h, c, ticks, c->timeout);