Browse Source

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

Andrei Pelinescu-Onciul 17 years ago
parent
commit
057063e685
2 changed files with 9 additions and 6 deletions
  1. 4 3
      tcp_main.c
  2. 5 3
      tcp_read.c

+ 4 - 3
tcp_main.c

@@ -250,6 +250,7 @@ static int tcp_proto_no=-1; /* tcp protocol number as returned by
 static io_wait_h io_h;
 
 static struct local_timer tcp_main_ltimer;
+static ticks_t tcp_main_prev_ticks;
 
 
 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)
 static inline void tcp_timer_run()
 {
 	ticks_t ticks;
-	static ticks_t prev_ticks=0;
 	
 	ticks=get_ticks_raw();
-	if (unlikely((ticks-prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
-	prev_ticks=ticks;
+	if (unlikely((ticks-tcp_main_prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
+	tcp_main_prev_ticks=ticks;
 	local_timer_run(&tcp_main_ltimer, ticks);
 }
 
@@ -3376,6 +3376,7 @@ void tcp_main_loop()
 	/* init: start watching all the fds*/
 	
 	/* init local timer */
+	tcp_main_prev_ticks=get_ticks_raw();
 	if (init_local_timer(&tcp_main_ltimer, get_ticks_raw())!=0){
 		LOG(L_ERR, "ERROR: init_tcp: failed to init local timer\n");
 		goto error;

+ 5 - 3
tcp_read.c

@@ -95,6 +95,7 @@ static io_wait_h io_w; /* io_wait handler*/
 static int tcpmain_sock=-1;
 
 static struct local_timer tcp_reader_ltimer;
+static ticks_t tcp_reader_prev_ticks;
 
 
 /* reads next available bytes
@@ -861,11 +862,11 @@ error:
 inline static void tcp_reader_timer_run()
 {
 	ticks_t ticks;
-	static ticks_t prev_ticks=0;
 	
 	ticks=get_ticks_raw();
-	if (unlikely((ticks-prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN)) return;
-	prev_ticks=ticks;
+	if (unlikely((ticks-tcp_reader_prev_ticks)<TCPCONN_TIMEOUT_MIN_RUN))
+		return;
+	tcp_reader_prev_ticks=ticks;
 	local_timer_run(&tcp_reader_ltimer, ticks);
 }
 
@@ -878,6 +879,7 @@ void tcp_receive_loop(int unix_sock)
 	tcpmain_sock=unix_sock; /* init com. socket */
 	if (init_io_wait(&io_w, get_max_open_fds(), tcp_poll_method)<0)
 		goto error;
+	tcp_reader_prev_ticks=get_ticks_raw();
 	if (init_local_timer(&tcp_reader_ltimer, get_ticks_raw())!=0)
 		goto error;
 	/* add the unix socket */