Browse code

core: add support for per-TCP connection lifetime

Camille Oudot authored on 19/02/2015 15:50:11
Showing 3 changed files
... ...
@@ -757,7 +757,7 @@ static void core_tcp_list(rpc_t* rpc, void* c)
757 757
 	char* state;
758 758
 	char* type;
759 759
 	struct tcp_connection* con;
760
-	int i, len, timeout;
760
+	int i, len, timeout, lifetime;
761 761
 
762 762
 	if (tcp_disable) {
763 763
 		rpc->fault(c, 500, "tcp support disabled");
... ...
@@ -789,6 +789,7 @@ static void core_tcp_list(rpc_t* rpc, void* c)
789 789
 				BUG("failed to convert destination ip");
790 790
 			dst_ip[len] = 0;
791 791
 			timeout = TICKS_TO_S(con->timeout - get_ticks_raw());
792
+			lifetime = TICKS_TO_S(con->lifetime);
792 793
 			switch(con->state) {
793 794
 				case S_CONN_ERROR:
794 795
 					state = "CONN_ERROR";
... ...
@@ -814,11 +815,12 @@ static void core_tcp_list(rpc_t* rpc, void* c)
814 814
 				default:
815 815
 					state = "UNKNOWN";
816 816
 			}
817
-			rpc->struct_add(handle, "dssddsdsd",
817
+			rpc->struct_add(handle, "dssdddsdsd",
818 818
 					"id", con->id,
819 819
 					"type", type,
820 820
 					"state", state,
821 821
 					"timeout", timeout,
822
+					"lifetime", lifetime,
822 823
 					"ref_count", con->refcnt,
823 824
 					"src_ip", src_ip,
824 825
 					"src_port", con->rcv.src_port,
... ...
@@ -204,6 +204,7 @@ struct tcp_connection{
204 204
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
205 205
 	struct timer_ln timer;
206 206
 	ticks_t timeout;/* connection timeout, after this it will be removed*/
207
+	ticks_t lifetime;/* connection lifetime */
207 208
 	unsigned id_hash; /* hash index in the id_hash */
208 209
 	struct tcp_connection* id_next; /* next, prev in id hash table */
209 210
 	struct tcp_connection* id_prev;
... ...
@@ -998,6 +998,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
998 998
 		c->type=PROTO_TCP;
999 999
 		c->rcv.proto=PROTO_TCP;
1000 1000
 		c->timeout=get_ticks_raw()+cfg_get(tcp, tcp_cfg, con_lifetime);
1001
+		c->lifetime = cfg_get(tcp, tcp_cfg, con_lifetime);
1001 1002
 	}
1002 1003
 	
1003 1004
 	return c;
... ...
@@ -3280,7 +3281,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
3280 3280
 			}
3281 3281
 			/* update the timeout*/
3282 3282
 			t=get_ticks_raw();
3283
-			con_lifetime=cfg_get(tcp, tcp_cfg, con_lifetime);
3283
+			con_lifetime=tcpconn->lifetime;
3284 3284
 			tcpconn->timeout=t+con_lifetime;
3285 3285
 			crt_timeout=con_lifetime;
3286 3286
 #ifdef TCP_ASYNC