]> err.no Git - varnish/commitdiff
Move defaults from varnishd.c to mgt_param.c and use regular functions
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 23 Aug 2006 06:55:18 +0000 (06:55 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 23 Aug 2006 06:55:18 +0000 (06:55 +0000)
for setting them.

Collapse all the 'timeout' functions.

Add pipe_timeout parameter.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@899 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/bin/varnishd/varnishd.c

index 98b7d9ffc6008fa4d2ab108396a91e6a884c6b65..4ca4c4219bfa86ce2b20fbe3a7402d2d57c7fb03 100644 (file)
@@ -12,6 +12,7 @@
 #include <sys/socket.h>
 
 #include "shmlog.h"
+#include "heritage.h"
 #include "cache.h"
 
 static void
@@ -83,7 +84,7 @@ PipeSession(struct sess *sp)
        while (fds[0].events || fds[1].events) {
                fds[0].revents = 0;
                fds[1].revents = 0;
-               i = poll(fds, 2, 600000);
+               i = poll(fds, 2, params->pipe_timeout * 1000);
                if (i != 1)
                        break;
                if (fds[0].revents)
index 2f57f69fe5c1e3a3f7825e296075cf83652f04c7..1dac9bb3f9688a09060b8a483ab949918f88c7d9 100644 (file)
@@ -42,6 +42,7 @@ struct params {
 
        /* Acceptor hints */
        unsigned                sess_timeout;
+       unsigned                pipe_timeout;
        unsigned                send_timeout;
 
        /* Management hints */
index 79ccff556fa38bc873e0ecfc5beb088abaa1ae38..2dedf627edcd382401269080013638631e748823 100644 (file)
@@ -22,6 +22,9 @@ void mgt_cli_start_child(int fdi, int fdo);
 void mgt_cli_stop_child(void);
 int mgt_cli_telnet(const char *T_arg);
 
+/* mgt_param.c */
+void MCF_ParamInit(void);
+
 /* mgt_vcc.c */
 void mgt_vcc_init(void);
 int mgt_vcc_default(const char *bflag, const char *fflag);
index 31d31297339beb9c233041d86dec0f1e473a9c33..b358a8216f3e83cfad0a97556a789b2ba1adb825 100644 (file)
@@ -22,10 +22,32 @@ struct parspec {
        const char      *name;
        tweak_t         *func;
        const char      *expl;
+       const char      *def;
 };
 
 /*--------------------------------------------------------------------*/
 
+static void
+tweak_generic_timeout(struct cli *cli, unsigned *dst, const char *arg)
+{
+       unsigned u;
+
+       if (arg != NULL) {
+               u = strtoul(arg, NULL, 0);
+               if (u == 0) {
+                       cli_out(cli, "Timeout must be greater than zero\n");
+                       cli_result(cli, CLIS_PARAM);
+                       return;
+               }
+               *dst = u;
+       }
+       if (cli == NULL)
+               return;
+       cli_out(cli, "%u [seconds]\n", *dst);
+}
+
+/*--------------------------------------------------------------------*/
+
 static void
 tweak_default_ttl(struct cli *cli, struct parspec *par, const char *arg)
 {
@@ -33,6 +55,8 @@ tweak_default_ttl(struct cli *cli, struct parspec *par, const char *arg)
        (void)par;
        if (arg != NULL)
                params->default_ttl = strtoul(arg, NULL, 0);
+       if (cli == NULL)
+               return;
        cli_out(cli, "%u [seconds]\n", params->default_ttl);
 }
 
@@ -53,6 +77,8 @@ tweak_thread_pool_min(struct cli *cli, struct parspec *par, const char *arg)
                }
                params->wthread_min = u;
        }
+       if (cli == NULL)
+               return;
        cli_out(cli, "%u [threads]\n", params->wthread_min);
 }
 
@@ -73,6 +99,8 @@ tweak_thread_pool_max(struct cli *cli, struct parspec *par, const char *arg)
                }
                params->wthread_max = u;
        }
+       if (cli == NULL)
+               return;
        if (params->wthread_max == UINT_MAX) 
                cli_out(cli, "unlimited\n");
        else 
@@ -84,20 +112,11 @@ tweak_thread_pool_max(struct cli *cli, struct parspec *par, const char *arg)
 static void
 tweak_thread_pool_timeout(struct cli *cli, struct parspec *par, const char *arg)
 {
-       unsigned u;
 
        (void)par;
-       if (arg != NULL) {
-               u = strtoul(arg, NULL, 0);
-               if (u == 0) {
-                       cli_out(cli, "Timeout must be greater than zero\n");
-                       cli_result(cli, CLIS_PARAM);
-                       return;
-               }
-               params->wthread_timeout = u;
-       }
-       cli_out(cli, "%u [seconds]\n", params->wthread_timeout);
+       tweak_generic_timeout(cli, &params->wthread_timeout, arg);
 }
+
 /*--------------------------------------------------------------------*/
 
 static void
@@ -115,6 +134,8 @@ tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg)
                }
                params->mem_workspace = u;
        }
+       if (cli == NULL)
+               return;
        cli_out(cli, "%u [bytes]\n", params->mem_workspace);
 }
 
@@ -123,19 +144,17 @@ tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg)
 static void
 tweak_sess_timeout(struct cli *cli, struct parspec *par, const char *arg)
 {
-       unsigned u;
+       (void)par;
+       tweak_generic_timeout(cli, &params->sess_timeout, arg);
+}
 
+/*--------------------------------------------------------------------*/
+
+static void
+tweak_pipe_timeout(struct cli *cli, struct parspec *par, const char *arg)
+{
        (void)par;
-       if (arg != NULL) {
-               u = strtoul(arg, NULL, 0);
-               if (u == 0) {
-                       cli_out(cli, "Timeout must be greater than zero\n");
-                       cli_result(cli, CLIS_PARAM);
-                       return;
-               }
-               params->sess_timeout = u;
-       }
-       cli_out(cli, "%u [seconds]\n", params->sess_timeout);
+       tweak_generic_timeout(cli, &params->pipe_timeout, arg);
 }
 
 /*--------------------------------------------------------------------*/
@@ -143,19 +162,8 @@ tweak_sess_timeout(struct cli *cli, struct parspec *par, const char *arg)
 static void
 tweak_send_timeout(struct cli *cli, struct parspec *par, const char *arg)
 {
-       unsigned u;
-
        (void)par;
-       if (arg != NULL) {
-               u = strtoul(arg, NULL, 0);
-               if (u == 0) {
-                       cli_out(cli, "Timeout must be greater than zero\n");
-                       cli_result(cli, CLIS_PARAM);
-                       return;
-               }
-               params->send_timeout = u;
-       }
-       cli_out(cli, "%u [seconds]\n", params->send_timeout);
+       tweak_generic_timeout(cli, &params->send_timeout, arg);
 }
 
 /*--------------------------------------------------------------------*/
@@ -175,6 +183,8 @@ tweak_auto_restart(struct cli *cli, struct parspec *par, const char *arg)
                }
                params->auto_restart = u;
        }
+       if (cli == NULL)
+               return;
        cli_out(cli, "%u {1 = yes, 0 = no}\n", params->auto_restart);
 }
 
@@ -205,46 +215,48 @@ static struct parspec parspec[] = {
                "made until they are fetched from the backend again.\n"
                "To force an immediate effect at the expense of a total "
                "flush of the cache use \"url.purge .\"\n"
-               "Default is 120 seconds. " },
+               "Default is 120 seconds. ", "120" },
+       { "thread_pool_max", tweak_thread_pool_max,
+               "The maximum number of threads in the worker pool.\n"
+               DELAYED_EFFECT
+               "Default is no limit.", "-1" },
        { "thread_pool_min", tweak_thread_pool_min,
                "The minimum number of threads in the worker pool.\n"
                DELAYED_EFFECT
                "Default is 1 thread. " 
-               "Minimum is 1 thread. " },
-       { "thread_pool_max", tweak_thread_pool_max,
-               "The maximum number of threads in the worker pool.\n"
-               DELAYED_EFFECT
-               "Default is no limit." },
+               "Minimum is 1 thread. ", "1" },
        { "thread_pool_timeout", tweak_thread_pool_timeout,
                "Thread dies after this many seconds of inactivity.\n"
                "Default is 10 seconds. "
-               "Minimum is 1 second. " },
+               "Minimum is 1 second. ", "10" },
        { "http_workspace", tweak_http_workspace,
                "Bytes of HTTP protocol workspace allocated. "
                "This space must be big enough for the entire HTTP protocol "
                "header and any edits done to it in the VCL code.\n"
                SHOULD_RESTART
                "Default is 4096 bytes. "
-               "Minimum is 1024 bytes. " },
+               "Minimum is 1024 bytes. ", "4096" },
        { "sess_timeout", tweak_sess_timeout,
                "Idle timeout for persistent sessions. "
                "If a HTTP request has not been received in this many "
                "seconds, the session is closed.\n"
-#ifdef HAVE_ACCEPT_FILTERS
-               DELAYED_EFFECT
-#endif
-               "Default is 15 seconds. " },
+               "Default is 5 seconds. ", "5" },
+       { "pipe_timeout", tweak_pipe_timeout,
+               "Idle timeout for PIPE sessions. "
+               "If nothing have been received in either directoin for "
+               "this many seconds, the session is closed.\n"
+               "Default is 60 seconds. ", "60" },
        { "send_timeout", tweak_send_timeout,
                "Send timeout for client connections. "
                "If no data has been sent to the client in this many seconds, "
                "the session is closed.\n"
                DELAYED_EFFECT
                "See getopt(3) under SO_SNDTIMEO for more information.\n"
-               "Default is 600 seconds. " },
+               "Default is 600 seconds. ", "600" },
        { "auto_restart", tweak_auto_restart,
                "Restart child process automatically if it dies. "
                "1 = yes, 0 = no.\n"
-               "Default is 1. " },
+               "Default is 1. ", "1" },
        { NULL, NULL, NULL }
 };
 
@@ -325,3 +337,13 @@ mcf_param_set(struct cli *cli, char **av, void *priv)
        }
 }
 
+/*--------------------------------------------------------------------*/
+
+void
+MCF_ParamInit(void)
+{
+       struct parspec *pp;
+
+       for (pp = parspec; pp->name != NULL; pp++)
+               pp->func(NULL, pp, pp->def);
+}
index ad1eea12c4488a26732a182f14a1f242afc386b5..9183a28435c39273ad11402cd3d6bf551125acb7 100644 (file)
@@ -336,15 +336,7 @@ main(int argc, char *argv[])
        params = &param;
        mgt_vcc_init(); 
 
-       /* XXX: move this to mgt_params.c ?? */
-       params->default_ttl = 120;
-       params->wthread_min = 1;
-       params->wthread_max = UINT_MAX;
-       params->wthread_timeout = 60;
-       params->mem_workspace = 4096;
-       params->sess_timeout = 5;
-       params->send_timeout = 600;
-       params->auto_restart = 1;
+       MCF_ParamInit();
 
        while ((o = getopt(argc, argv, "a:b:df:h:s:t:T:Vw:")) != -1)
                switch (o) {