[master] c105995 Move waiter related code from cache_acceptor.c to its own file.
Poul-Henning Kamp
phk at varnish-cache.org
Sat Sep 17 16:09:28 CEST 2011
commit c10599526e8f43d9c999a470d530f643752d2564
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sat Sep 17 14:08:17 2011 +0000
Move waiter related code from cache_acceptor.c to its own file.
(Sort Makefile.am::SOURCES which had become unsorted)
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 288f1f1..e4ff980 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -11,10 +11,6 @@ dist_man_MANS = varnishd.1
varnishd_SOURCES = \
cache_acceptor.c \
- cache_waiter_epoll.c \
- cache_waiter_kqueue.c \
- cache_waiter_poll.c \
- cache_waiter_ports.c \
cache_backend.c \
cache_backend_cfg.c \
cache_backend_poll.c \
@@ -22,20 +18,20 @@ varnishd_SOURCES = \
cache_center.c \
cache_cli.c \
cache_dir.c \
- cache_dir_random.c \
cache_dir_dns.c \
+ cache_dir_random.c \
cache_dir_round_robin.c \
+ cache_esi_deliver.c \
cache_esi_fetch.c \
cache_esi_parse.c \
- cache_esi_deliver.c \
cache_expire.c \
cache_fetch.c \
cache_gzip.c \
cache_hash.c \
cache_http.c \
cache_httpconn.c \
- cache_main.c \
cache_lck.c \
+ cache_main.c \
cache_panic.c \
cache_pipe.c \
cache_pool.c \
@@ -48,6 +44,11 @@ varnishd_SOURCES = \
cache_vrt_re.c \
cache_vrt_var.c \
cache_vrt_vmod.c \
+ cache_waiter.c \
+ cache_waiter_epoll.c \
+ cache_waiter_kqueue.c \
+ cache_waiter_poll.c \
+ cache_waiter_ports.c \
cache_wrk.c \
cache_wrw.c \
cache_ws.c \
@@ -63,6 +64,7 @@ varnishd_SOURCES = \
mgt_vcc.c \
rfc2616.c \
stevedore.c \
+ stevedore_utils.c \
storage_file.c \
storage_malloc.c \
storage_persistent.c \
@@ -71,7 +73,6 @@ varnishd_SOURCES = \
storage_persistent_subr.c \
storage_synth.c \
storage_umem.c \
- stevedore_utils.c \
varnishd.c \
vsm.c
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 2f43ff8..5d44092 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -649,7 +649,6 @@ void vca_return_session(struct sess *sp);
void VCA_Prep(struct sess *sp);
void VCA_Init(void);
void VCA_Shutdown(void);
-const char *VCA_waiter_name(void);
extern pthread_t VCA_thread;
/* cache_backend.c */
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 46f955b..3781f47 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -30,14 +30,10 @@
#include "config.h"
-#include <stdio.h>
#include <errno.h>
#include <poll.h>
-#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <sys/uio.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -46,22 +42,6 @@
#include "cache.h"
#include "cache_waiter.h"
-static struct waiter * const vca_waiters[] = {
-#if defined(HAVE_KQUEUE)
- &waiter_kqueue,
-#endif
-#if defined(HAVE_EPOLL_CTL)
- &waiter_epoll,
-#endif
-#if defined(HAVE_PORT_CREATE)
- &waiter_ports,
-#endif
- &waiter_poll,
- NULL,
-};
-
-static struct waiter const *vca_act;
-
static void *waiter_priv;
pthread_t VCA_thread;
@@ -69,21 +49,6 @@ static struct timeval tv_sndtimeo;
static struct timeval tv_rcvtimeo;
/*--------------------------------------------------------------------
- * Report waiter name to panics
- */
-
-const char *
-VCA_waiter_name(void)
-{
-
- if (vca_act != NULL)
- return (vca_act->name);
- else
- return ("no_waiter");
-}
-
-
-/*--------------------------------------------------------------------
* We want to get out of any kind of trouble-hit TCP connections as fast
* as absolutely possible, so we set them LINGER enabled with zero timeout,
* so that even if there are outstanding write data on the socket, a close(2)
@@ -347,7 +312,7 @@ vca_return_session(struct sess *sp)
*/
if (VTCP_nonblocking(sp->fd))
SES_Close(sp, "remote closed");
- vca_act->pass(waiter_priv, sp);
+ waiter->pass(waiter_priv, sp);
}
/*--------------------------------------------------------------------*/
@@ -360,17 +325,14 @@ ccf_start(struct cli *cli, const char * const *av, void *priv)
(void)av;
(void)priv;
- if (vca_act == NULL)
- vca_act = vca_waiters[0];
-
- AN(vca_act);
- AN(vca_act->name);
- AN(vca_act->init);
- AN(vca_act->pass);
+ AN(waiter);
+ AN(waiter->name);
+ AN(waiter->init);
+ AN(waiter->pass);
- waiter_priv = vca_act->init();
+ waiter_priv = waiter->init();
AZ(pthread_create(&VCA_thread, NULL, vca_acct, NULL));
- VSL(SLT_Debug, 0, "Acceptor is %s", vca_act->name);
+ VSL(SLT_Debug, 0, "Acceptor is %s", waiter->name);
}
/*--------------------------------------------------------------------*/
@@ -424,37 +386,3 @@ VCA_Shutdown(void)
(void)close(i);
}
}
-
-void
-VCA_tweak_waiter(struct cli *cli, const char *arg)
-{
- int i;
-
- ASSERT_MGT();
-
- if (arg == NULL) {
- if (vca_act == NULL)
- VCLI_Out(cli, "default");
- else
- VCLI_Out(cli, "%s", vca_act->name);
-
- VCLI_Out(cli, " (");
- for (i = 0; vca_waiters[i] != NULL; i++)
- VCLI_Out(cli, "%s%s", i == 0 ? "" : ", ",
- vca_waiters[i]->name);
- VCLI_Out(cli, ")");
- return;
- }
- if (!strcmp(arg, "default")) {
- vca_act = NULL;
- return;
- }
- for (i = 0; vca_waiters[i]; i++) {
- if (!strcmp(arg, vca_waiters[i]->name)) {
- vca_act = vca_waiters[i];
- return;
- }
- }
- VCLI_Out(cli, "Unknown waiter");
- VCLI_SetResult(cli, CLIS_PARAM);
-}
diff --git a/bin/varnishd/cache_main.c b/bin/varnishd/cache_main.c
index 4312393..3489530 100644
--- a/bin/varnishd/cache_main.c
+++ b/bin/varnishd/cache_main.c
@@ -37,6 +37,7 @@
#include "cache.h"
#include "stevedore.h"
#include "hash_slinger.h"
+#include "cache_waiter.h"
/*--------------------------------------------------------------------
* Per thread storage for the session currently being processed by
@@ -103,6 +104,7 @@ child_main(void)
LCK_Init(); /* Second, locking */
+ WAIT_Init();
PAN_Init();
CLI_Init();
Fetch_Init();
diff --git a/bin/varnishd/cache_panic.c b/bin/varnishd/cache_panic.c
index 2f0921d..b243832 100644
--- a/bin/varnishd/cache_panic.c
+++ b/bin/varnishd/cache_panic.c
@@ -44,6 +44,7 @@
#include "cache.h"
#include "vsm.h"
#include "cache_backend.h"
+#include "cache_waiter.h"
#include "vcl.h"
#include "libvcl.h"
@@ -341,7 +342,7 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
VSB_printf(vsp, "thread = (%s)\n", q);
VSB_printf(vsp, "ident = %s,%s\n",
- VSB_data(vident) + 1, VCA_waiter_name());
+ VSB_data(vident) + 1, WAIT_GetName());
pan_backtrace();
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 982d8fe..eb2e62d 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -322,7 +322,7 @@ RES_WriteObj(struct sess *sp)
!(sp->wrk->res_mode & RES_ESI_CHILD))
WRW_EndChunk(sp->wrk);
- if (WRW_FlushRelease(sp->wrk))
+ if (WRW_FlushRelease(sp->wrk) && sp->fd >= 0)
SES_Close(sp, "remote closed");
}
diff --git a/bin/varnishd/cache_waiter.c b/bin/varnishd/cache_waiter.c
new file mode 100644
index 0000000..cd3e007
--- /dev/null
+++ b/bin/varnishd/cache_waiter.c
@@ -0,0 +1,109 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+
+#include "vcli.h"
+#include "cli_priv.h"
+#include "cache.h"
+#include "cache_waiter.h"
+
+static const struct waiter * const vca_waiters[] = {
+ #if defined(HAVE_KQUEUE)
+ &waiter_kqueue,
+ #endif
+ #if defined(HAVE_EPOLL_CTL)
+ &waiter_epoll,
+ #endif
+ #if defined(HAVE_PORT_CREATE)
+ &waiter_ports,
+ #endif
+ &waiter_poll,
+ NULL,
+};
+
+struct waiter const * waiter;
+
+const char *
+WAIT_GetName(void)
+{
+
+ if (waiter != NULL)
+ return (waiter->name);
+ else
+ return ("no_waiter");
+}
+
+void
+WAIT_tweak_waiter(struct cli *cli, const char *arg)
+{
+ int i;
+
+ ASSERT_MGT();
+
+ if (arg == NULL) {
+ if (waiter == NULL)
+ VCLI_Out(cli, "default");
+ else
+ VCLI_Out(cli, "%s", waiter->name);
+
+ VCLI_Out(cli, " (");
+ for (i = 0; vca_waiters[i] != NULL; i++)
+ VCLI_Out(cli, "%s%s", i == 0 ? "" : ", ",
+ vca_waiters[i]->name);
+ VCLI_Out(cli, ")");
+ return;
+ }
+ if (!strcmp(arg, "default")) {
+ waiter = NULL;
+ return;
+ }
+ for (i = 0; vca_waiters[i]; i++) {
+ if (!strcmp(arg, vca_waiters[i]->name)) {
+ waiter = vca_waiters[i];
+ return;
+ }
+ }
+ VCLI_Out(cli, "Unknown waiter");
+ VCLI_SetResult(cli, CLIS_PARAM);
+}
+
+void
+WAIT_Init(void)
+{
+
+ if (waiter == NULL)
+ waiter = vca_waiters[0];
+
+ AN(waiter);
+ AN(waiter->name);
+ AN(waiter->init);
+ AN(waiter->pass);
+}
diff --git a/bin/varnishd/cache_waiter.h b/bin/varnishd/cache_waiter.h
index 86eb2cb..4377f82 100644
--- a/bin/varnishd/cache_waiter.h
+++ b/bin/varnishd/cache_waiter.h
@@ -39,20 +39,25 @@ struct waiter {
waiter_pass_f *pass;
};
+extern struct waiter const * waiter;
+
#if defined(HAVE_EPOLL_CTL)
-extern struct waiter waiter_epoll;
+extern const struct waiter waiter_epoll;
#endif
#if defined(HAVE_KQUEUE)
-extern struct waiter waiter_kqueue;
+extern const struct waiter waiter_kqueue;
#endif
-extern struct waiter waiter_poll;
-
#if defined(HAVE_PORT_CREATE)
-extern struct waiter waiter_ports;
+extern const struct waiter waiter_ports;
#endif
+extern const struct waiter waiter_poll;
+
/* cache_session.c */
void SES_Handle(struct sess *sp, int status);
+const char *WAIT_GetName(void);
+void WAIT_tweak_waiter(struct cli *cli, const char *arg);
+void WAIT_Init(void);
diff --git a/bin/varnishd/cache_waiter_epoll.c b/bin/varnishd/cache_waiter_epoll.c
index acb8e13..28776cd 100644
--- a/bin/varnishd/cache_waiter_epoll.c
+++ b/bin/varnishd/cache_waiter_epoll.c
@@ -269,7 +269,7 @@ vwe_init(void)
/*--------------------------------------------------------------------*/
-struct waiter waiter_epoll = {
+const struct waiter waiter_epoll = {
.name = "epoll",
.init = vwe_init,
.pass = vwe_pass,
diff --git a/bin/varnishd/cache_waiter_kqueue.c b/bin/varnishd/cache_waiter_kqueue.c
index 7e6b10f..7decfea 100644
--- a/bin/varnishd/cache_waiter_kqueue.c
+++ b/bin/varnishd/cache_waiter_kqueue.c
@@ -237,7 +237,7 @@ vwk_init(void)
/*--------------------------------------------------------------------*/
-struct waiter waiter_kqueue = {
+const struct waiter waiter_kqueue = {
.name = "kqueue",
.init = vwk_init,
.pass = vwk_pass,
diff --git a/bin/varnishd/cache_waiter_poll.c b/bin/varnishd/cache_waiter_poll.c
index f44daa9..3a211bd 100644
--- a/bin/varnishd/cache_waiter_poll.c
+++ b/bin/varnishd/cache_waiter_poll.c
@@ -227,7 +227,7 @@ vwp_poll_init(void)
/*--------------------------------------------------------------------*/
-struct waiter waiter_poll = {
+const struct waiter waiter_poll = {
.name = "poll",
.init = vwp_poll_init,
.pass = vwp_poll_pass,
diff --git a/bin/varnishd/cache_waiter_ports.c b/bin/varnishd/cache_waiter_ports.c
index 329ee23..695e9c0 100644
--- a/bin/varnishd/cache_waiter_ports.c
+++ b/bin/varnishd/cache_waiter_ports.c
@@ -275,7 +275,7 @@ vws_init(void)
/*--------------------------------------------------------------------*/
-struct waiter waiter_ports = {
+const struct waiter waiter_ports = {
.name = "ports",
.init = vws_init,
.pass = vws_pass
diff --git a/bin/varnishd/common.h b/bin/varnishd/common.h
index 1a64cf3..3708b45 100644
--- a/bin/varnishd/common.h
+++ b/bin/varnishd/common.h
@@ -33,9 +33,6 @@ struct cli;
extern pid_t mgt_pid;
#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
-/* cache_acceptor.c */
-void VCA_tweak_waiter(struct cli *cli, const char *arg);
-
/* mgt_shmem.c */
extern struct VSC_C_main *VSC_C_main;
diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c
index 33101bb..b9067e7 100644
--- a/bin/varnishd/mgt_param.c
+++ b/bin/varnishd/mgt_param.c
@@ -48,6 +48,7 @@
#include "heritage.h"
#include "vparam.h"
+#include "cache_waiter.h"
#include "vss.h"
@@ -438,7 +439,7 @@ tweak_waiter(struct cli *cli, const struct parspec *par, const char *arg)
/* XXX should have tweak_generic_string */
(void)par;
- VCA_tweak_waiter(cli, arg);
+ WAIT_tweak_waiter(cli, arg);
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list