Commit c1059952 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move waiter related code from cache_acceptor.c to its own file.

(Sort Makefile.am::SOURCES which had become unsorted)
parent 0ad2c29e
......@@ -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
......
......@@ -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 */
......
......@@ -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,43 +42,12 @@
#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;
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,
......@@ -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);
}
......@@ -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();
......
......@@ -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();
......
......@@ -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");
}
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@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);
}
......@@ -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);
......@@ -269,7 +269,7 @@ vwe_init(void)
/*--------------------------------------------------------------------*/
struct waiter waiter_epoll = {
const struct waiter waiter_epoll = {
.name = "epoll",
.init = vwe_init,
.pass = vwe_pass,
......
......@@ -237,7 +237,7 @@ vwk_init(void)
/*--------------------------------------------------------------------*/
struct waiter waiter_kqueue = {
const struct waiter waiter_kqueue = {
.name = "kqueue",
.init = vwk_init,
.pass = vwk_pass,
......
......@@ -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,
......
......@@ -275,7 +275,7 @@ vws_init(void)
/*--------------------------------------------------------------------*/
struct waiter waiter_ports = {
const struct waiter waiter_ports = {
.name = "ports",
.init = vws_init,
.pass = vws_pass
......
......@@ -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;
......
......@@ -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);
}
/*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment