tcp: dyn. config fix for tcp_con_lifetime
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Mon, 9 Mar 2009 13:39:10 +0000 (13:39 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Mon, 9 Mar 2009 13:39:10 +0000 (13:39 +0000)
- cfg.set_delayed_int didn't work (fixup tried to modify another
  config variable which doesn't work with cfg.set_delayed*)

cfg.y
core_cmd.c
tcp_options.c
tcp_options.h

diff --git a/cfg.y b/cfg.y
index 04d5d3e..861dc14 100644 (file)
--- a/cfg.y
+++ b/cfg.y
 #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
index c22e59e..48759fb 100644 (file)
@@ -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,
index 21591d1..e7a02dd 100644 (file)
@@ -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;
 }
 
index 24df41e..e4a1ee7 100644 (file)
 
 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;