Browse code

- tcp: fix local timer intialization (proper prev_ticks init.)

Andrei Pelinescu-Onciul authored on 08/01/2008 13:11:30
Showing 2 changed files
... ...
@@ -250,6 +250,7 @@ static int tcp_proto_no=-1; /* tcp protocol number as returned by
250 250
 static io_wait_h io_h;
251 251
 
252 252
 static struct local_timer tcp_main_ltimer;
253
+static ticks_t tcp_main_prev_ticks;
253 254
 
254 255
 
255 256
 static ticks_t tcpconn_main_timeout(ticks_t , struct timer_ln* , void* );
... ...
@@ -3281,11 +3282,10 @@ static ticks_t tcpconn_main_timeout(ticks_t t, struct timer_ln* tl, void* data)
3281 3281
 static inline void tcp_timer_run()
3282 3282
 {
3283 3283
 	ticks_t ticks;
3284
-	static ticks_t prev_ticks=0;
3285 3284
 	
3286 3285
 	ticks=get_ticks_raw();
3287
-	if (unlikely((ticks-prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
3288
-	prev_ticks=ticks;
3286
+	if (unlikely((ticks-tcp_main_prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
3287
+	tcp_main_prev_ticks=ticks;
3289 3288
 	local_timer_run(&tcp_main_ltimer, ticks);
3290 3289
 }
3291 3290
 
... ...
@@ -3376,6 +3376,7 @@ void tcp_main_loop()
3376 3376
 	/* init: start watching all the fds*/
3377 3377
 	
3378 3378
 	/* init local timer */
3379
+	tcp_main_prev_ticks=get_ticks_raw();
3379 3380
 	if (init_local_timer(&tcp_main_ltimer, get_ticks_raw())!=0){
3380 3381
 		LOG(L_ERR, "ERROR: init_tcp: failed to init local timer\n");
3381 3382
 		goto error;
... ...
@@ -95,6 +95,7 @@ static io_wait_h io_w; /* io_wait handler*/
95 95
 static int tcpmain_sock=-1;
96 96
 
97 97
 static struct local_timer tcp_reader_ltimer;
98
+static ticks_t tcp_reader_prev_ticks;
98 99
 
99 100
 
100 101
 /* reads next available bytes
... ...
@@ -861,11 +862,11 @@ error:
861 861
 inline static void tcp_reader_timer_run()
862 862
 {
863 863
 	ticks_t ticks;
864
-	static ticks_t prev_ticks=0;
865 864
 	
866 865
 	ticks=get_ticks_raw();
867
-	if (unlikely((ticks-prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
868
-	prev_ticks=ticks;
866
+	if (unlikely((ticks-tcp_reader_prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN))
867
+		return;
868
+	tcp_reader_prev_ticks=ticks;
869 869
 	local_timer_run(&tcp_reader_ltimer, ticks);
870 870
 }
871 871
 
... ...
@@ -878,6 +879,7 @@ void tcp_receive_loop(int unix_sock)
878 878
 	tcpmain_sock=unix_sock; /* init com. socket */
879 879
 	if (init_io_wait(&io_w, get_max_open_fds(), tcp_poll_method)<0)
880 880
 		goto error;
881
+	tcp_reader_prev_ticks=get_ticks_raw();
881 882
 	if (init_local_timer(&tcp_reader_ltimer, get_ticks_raw())!=0)
882 883
 		goto error;
883 884
 	/* add the unix socket */