Browse code

- fix: io_watch_add moved to the end of CONN_QUEUED_WRITE (so that if sigio_rt is used and the io_watch_add call ends up in the connection destruction via handle_io() the code is still safe)

Andrei Pelinescu-Onciul authored on 10/01/2008 15:18:45
Showing 1 changed files
... ...
@@ -1621,7 +1621,7 @@ no_id:
1621 1621
 				/* do connect and if src ip or port changed, update the 
1622 1622
 				 * aliases */
1623 1623
 				if (unlikely((fd=tcpconn_finish_connect(c, from))<0)){
1624
-					LOG(L_ERR, "ERROR: tcp_send: tcpconn_finsish_connect(%p)"
1624
+					LOG(L_ERR, "ERROR: tcp_send: tcpconn_finish_connect(%p)"
1625 1625
 							" failed\n", c);
1626 1626
 					goto conn_wait_error;
1627 1627
 				}
... ...
@@ -2775,6 +2775,20 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
2775 2775
 							!(tcpconn->flags & F_CONN_HASHED) ))
2776 2776
 				break;
2777 2777
 			if (!(tcpconn->flags & F_CONN_WRITE_W)){
2778
+				t=get_ticks_raw();
2779
+				if (likely((tcpconn->flags & F_CONN_MAIN_TIMER) && 
2780
+					(TICKS_LT(tcpconn->wbuf_q.wr_timeout, tcpconn->timeout)) &&
2781
+						TICKS_LT(t, tcpconn->wbuf_q.wr_timeout) )){
2782
+					/* _wbufq_nonempty() is guaranteed here */
2783
+					/* update the timer */
2784
+					local_timer_del(&tcp_main_ltimer, &tcpconn->timer);
2785
+					local_timer_reinit(&tcpconn->timer);
2786
+					local_timer_add(&tcp_main_ltimer, &tcpconn->timer,
2787
+										tcpconn->wbuf_q.wr_timeout-t, t);
2788
+					DBG("tcp_main: handle_ser_child: CONN_QUEUED_WRITE; %p "
2789
+							"timeout adjusted to %d s\n", tcpconn, 
2790
+							TICKS_TO_S(tcpconn->wbuf_q.wr_timeout-t));
2791
+				}
2778 2792
 				if (tcpconn->flags& F_CONN_REMOVED){
2779 2793
 					if (unlikely(io_watch_add(&io_h, tcpconn->s, POLLOUT,
2780 2794
 												F_TCPCONN, tcpconn)<0)){
... ...
@@ -2797,20 +2811,6 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
2797 2797
 					}
2798 2798
 				}
2799 2799
 				tcpconn->flags|=F_CONN_WRITE_W;
2800
-				t=get_ticks_raw();
2801
-				if (likely((tcpconn->flags & F_CONN_MAIN_TIMER) && 
2802
-					(TICKS_LT(tcpconn->wbuf_q.wr_timeout, tcpconn->timeout)) &&
2803
-						TICKS_LT(t, tcpconn->wbuf_q.wr_timeout) )){
2804
-					/* _wbufq_nonempty() is guaranteed here */
2805
-					/* update the timer */
2806
-					local_timer_del(&tcp_main_ltimer, &tcpconn->timer);
2807
-					local_timer_reinit(&tcpconn->timer);
2808
-					local_timer_add(&tcp_main_ltimer, &tcpconn->timer,
2809
-										tcpconn->wbuf_q.wr_timeout-t, t);
2810
-					DBG("tcp_main: handle_ser_child: CONN_QUEUED_WRITE; %p "
2811
-							"timeout adjusted to %d s\n", tcpconn, 
2812
-							TICKS_TO_S(tcpconn->wbuf_q.wr_timeout-t));
2813
-				}
2814 2800
 			}else{
2815 2801
 				LOG(L_WARN, "tcp_main: hanlder_ser_child: connection %p"
2816 2802
 							" already watched for write\n", tcpconn);
... ...
@@ -3141,6 +3141,7 @@ inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, short ev,
3141 3141
 #endif /* TCP_BUF_WRITE */
3142 3142
 			if (unlikely(io_watch_del(&io_h, tcpconn->s, fd_i, 0)==-1))
3143 3143
 				goto error;
3144
+		DBG("tcp: DBG: sendig to child, events %x\n", ev);
3144 3145
 		tcpconn->flags|=F_CONN_REMOVED|F_CONN_READER;
3145 3146
 		local_timer_del(&tcp_main_ltimer, &tcpconn->timer);
3146 3147
 		tcpconn->flags&=~F_CONN_MAIN_TIMER;