Pārlūkot izejas kodu

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 16 gadi atpakaļ
vecāks
revīzija
9a74e06a15
4 mainītis faili ar 15 papildinājumiem un 21 dzēšanām
  1. 5 1
      cfg.y
  2. 1 1
      core_cmd.c
  3. 7 16
      tcp_options.c
  4. 2 3
      tcp_options.h

+ 5 - 1
cfg.y

@@ -125,6 +125,7 @@
 #ifdef CORE_TLS
 #include "tls/tls_config.h"
 #endif
+#include "timer_ticks.h"
 
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
@@ -797,7 +798,10 @@ assign_stm:
 	| TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
 	| TCP_CON_LIFETIME EQUAL NUMBER {
 		#ifdef USE_TCP
-			tcp_default_cfg.con_lifetime_s=$3;
+			if ($3<0)
+				tcp_default_cfg.con_lifetime=-1;
+			else
+				tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
 		#else
 			warn("tcp support not compiled in");
 		#endif

+ 1 - 1
core_cmd.c

@@ -568,7 +568,7 @@ static void core_tcp_options(rpc_t* rpc, void* c)
 		rpc->struct_add(handle, "ddddddddddddddddddddddd",
 			"connect_timeout", t.connect_timeout_s,
 			"send_timeout",  t.send_timeout_s,
-			"connection_lifetime",  t.con_lifetime_s,
+			"connection_lifetime",  TICKS_TO_S(t.con_lifetime),
 			"max_connections(soft)", t.max_connections,
 			"no_connect",	t.no_connect,
 			"fd_cache",		t.fd_cache,

+ 7 - 16
tcp_options.c

@@ -83,7 +83,7 @@ static cfg_def_t tcp_cfg_def[] = {
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
 		"in seconds"},
 	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_con_lt,      0,
+						MAX_TCP_CON_LIFETIME,               fix_con_lt,      0,
 		"connection lifetime (in seconds)"},
 	{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1,
 													       fix_max_conns,    0,
@@ -133,9 +133,6 @@ static cfg_def_t tcp_cfg_def[] = {
 	{ "wq_timeout_ticks",   CFG_VAR_INT | CFG_READONLY, 0,
 									MAX_TCP_CON_LIFETIME,         0,         0,
 		"internal send_timeout value in ticks, used in async. mode"},
-	{ "con_lifetime_ticks", CFG_VAR_INT | CFG_READONLY, 0,
-									MAX_TCP_CON_LIFETIME,         0,         0,
-		"internal connection_lifetime value, converted to ticks"},
 	{0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -147,7 +144,7 @@ void init_tcp_options()
 {
 	tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT;
 	tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT;
-	tcp_default_cfg.con_lifetime_s=DEFAULT_TCP_CONNECTION_LIFETIME_S;
+	tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S);
 	tcp_default_cfg.max_connections=tcp_max_connections;
 #ifdef TCP_ASYNC
 	tcp_default_cfg.async=1;
@@ -241,14 +238,10 @@ static int fix_send_to(void* cfg_h, str* name, void** val)
 static int fix_con_lt(void* cfg_h, str* name, void** val)
 {
 	int v;
-	v=(int)(long)*val;
-	fix_timeout("tcp_connection_lifetime", &v,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	v=S_TO_TICKS((int)(long)*val);
+	fix_timeout("tcp_connection_lifetime", &v, 
+					MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
 	*val=(void*)(long)v;
-#ifdef TCP_ASYNC
-	((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
-#endif /* TCP_ASYNC */
 	return 0;
 }
 
@@ -324,14 +317,12 @@ void tcp_options_check()
 	fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout_s,
 						DEFAULT_TCP_SEND_TIMEOUT,
 						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
-	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime_s,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
+						MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME);
 	/* compute timeout in ticks */
 #ifdef TCP_ASYNC
 	tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s);
 #endif /* TCP_ASYNC */
-	tcp_default_cfg.con_lifetime=S_TO_TICKS(tcp_default_cfg.con_lifetime_s);
 	tcp_default_cfg.max_connections=tcp_max_connections;
 }
 

+ 2 - 3
tcp_options.h

@@ -111,9 +111,9 @@
 
 struct cfg_group_tcp{
 	/* ser tcp options, low level */
-	int connect_timeout_s; /* in s, used only in non-async mode */
+	int connect_timeout_s; /* in s */
 	int send_timeout_s; /* in s */
-	int con_lifetime_s; /* in s */
+	int con_lifetime; /* s fixed to ticks */
 	int max_connections;
 	int no_connect; /* do not open any new tcp connection (but accept them) */
 	int fd_cache; /* on /off */
@@ -140,7 +140,6 @@ struct cfg_group_tcp{
 	int new_conn_alias_flags;
 	/* internal, "fixed" vars */
 	unsigned int tcp_wq_timeout; /* in ticks, timeout for queued writes */
-	unsigned int con_lifetime; /* in ticks, see con_lifetime_s */
 };
 
 extern struct cfg_group_tcp tcp_default_cfg;