Browse code

tcp: dyn. config fix for tcp_con_lifetime

- cfg.set_delayed_int didn't work (fixup tried to modify another
config variable which doesn't work with cfg.set_delayed*)

Andrei Pelinescu-Onciul authored on 09/03/2009 13:39:10
Showing 4 changed files
... ...
@@ -125,6 +125,7 @@
125 125
 #ifdef CORE_TLS
126 126
 #include "tls/tls_config.h"
127 127
 #endif
128
+#include "timer_ticks.h"
128 129
 
129 130
 #ifdef DEBUG_DMALLOC
130 131
 #include <dmalloc.h>
... ...
@@ -797,7 +798,10 @@ assign_stm:
797 797
 	| TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
798 798
 	| TCP_CON_LIFETIME EQUAL NUMBER {
799 799
 		#ifdef USE_TCP
800
-			tcp_default_cfg.con_lifetime_s=$3;
800
+			if ($3<0)
801
+				tcp_default_cfg.con_lifetime=-1;
802
+			else
803
+				tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
801 804
 		#else
802 805
 			warn("tcp support not compiled in");
803 806
 		#endif
... ...
@@ -568,7 +568,7 @@ static void core_tcp_options(rpc_t* rpc, void* c)
568 568
 		rpc->struct_add(handle, "ddddddddddddddddddddddd",
569 569
 			"connect_timeout", t.connect_timeout_s,
570 570
 			"send_timeout",  t.send_timeout_s,
571
-			"connection_lifetime",  t.con_lifetime_s,
571
+			"connection_lifetime",  TICKS_TO_S(t.con_lifetime),
572 572
 			"max_connections(soft)", t.max_connections,
573 573
 			"no_connect",	t.no_connect,
574 574
 			"fd_cache",		t.fd_cache,
... ...
@@ -83,7 +83,7 @@ static cfg_def_t tcp_cfg_def[] = {
83 83
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
84 84
 		"in seconds"},
85 85
 	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
86
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_con_lt,      0,
86
+						MAX_TCP_CON_LIFETIME,               fix_con_lt,      0,
87 87
 		"connection lifetime (in seconds)"},
88 88
 	{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1,
89 89
 													       fix_max_conns,    0,
... ...
@@ -133,9 +133,6 @@ static cfg_def_t tcp_cfg_def[] = {
133 133
 	{ "wq_timeout_ticks",   CFG_VAR_INT | CFG_READONLY, 0,
134 134
 									MAX_TCP_CON_LIFETIME,         0,         0,
135 135
 		"internal send_timeout value in ticks, used in async. mode"},
136
-	{ "con_lifetime_ticks", CFG_VAR_INT | CFG_READONLY, 0,
137
-									MAX_TCP_CON_LIFETIME,         0,         0,
138
-		"internal connection_lifetime value, converted to ticks"},
139 136
 	{0, 0, 0, 0, 0, 0, 0}
140 137
 };
141 138
 
... ...
@@ -147,7 +144,7 @@ void init_tcp_options()
147 147
 {
148 148
 	tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT;
149 149
 	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
150
-	tcp_default_cfg.con_lifetime_s=DEFAULT_TCP_CONNECTION_LIFETIME_S;
150
+	tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S);
151 151
 	tcp_default_cfg.max_connections=tcp_max_connections;
152 152
 #ifdef TCP_ASYNC
153 153
 	tcp_default_cfg.async=1;
... ...
@@ -241,14 +238,10 @@ static int fix_send_to(void* cfg_h, str* name, void** val)
241 241
 static int fix_con_lt(void* cfg_h, str* name, void** val)
242 242
 {
243 243
 	int v;
244
-	v=(int)(long)*val;
245
-	fix_timeout("tcp_connection_lifetime", &v,
246
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
247
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
244
+	v=S_TO_TICKS((int)(long)*val);
245
+	fix_timeout("tcp_connection_lifetime", &v, 
246
+					MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
248 247
 	*val=(void*)(long)v;
249
-#ifdef TCP_ASYNC
250
-	((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
251
-#endif /* TCP_ASYNC */
252 248
 	return 0;
253 249
 }
254 250
 
... ...
@@ -324,14 +317,12 @@ void tcp_options_check()
324 324
 	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout_s,
325 325
 						DEFAULT_TCP_SEND_TIMEOUT,
326 326
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
327
-	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime_s,
328
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
329
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
327
+	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
328
+						MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
330 329
 	/* compute timeout in ticks */
331 330
 #ifdef TCP_ASYNC
332 331
 	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
333 332
 #endif /* TCP_ASYNC */
334
-	tcp_default_cfg.con_lifetime=S_TO_TICKS(tcp_default_cfg.con_lifetime_s);
335 333
 	tcp_default_cfg.max_connections=tcp_max_connections;
336 334
 }
337 335
 
... ...
@@ -111,9 +111,9 @@
111 111
 
112 112
 struct cfg_group_tcp{
113 113
 	/* ser tcp options, low level */
114
-	int connect_timeout_s; /* in s, used only in non-async mode */
114
+	int connect_timeout_s; /* in s */
115 115
 	int send_timeout_s; /* in s */
116
-	int con_lifetime_s; /* in s */
116
+	int con_lifetime; /* s fixed to ticks */
117 117
 	int max_connections;
118 118
 	int no_connect; /* do not open any new tcp connection (but accept them) */
119 119
 	int fd_cache; /* on /off */
... ...
@@ -140,7 +140,6 @@ struct cfg_group_tcp{
140 140
 	int new_conn_alias_flags;
141 141
 	/* internal, "fixed" vars */
142 142
 	unsigned int tcp_wq_timeout; /* in ticks, timeout for queued writes */
143
-	unsigned int con_lifetime; /* in ticks, see con_lifetime_s */
144 143
 };
145 144
 
146 145
 extern struct cfg_group_tcp tcp_default_cfg;