Commit 722f654f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a STV_Foreach() iterator, to isolate the clue to Transients

special treatment.
parent a83b79b9
......@@ -104,10 +104,9 @@ run_vcc(void *priv)
VCC_Err_Unref(vcc, mgt_vcc_err_unref);
VCC_Allow_InlineC(vcc, mgt_vcc_allow_inline_c);
VCC_Unsafe_Path(vcc, mgt_vcc_unsafe_path);
VTAILQ_FOREACH(stv, &stv_stevedores, list)
STV_Foreach(stv)
VCC_Predef(vcc, "VCL_STEVEDORE", stv->ident);
mgt_vcl_export_labels(vcc);
VCC_Predef(vcc, "VCL_STEVEDORE", stv_transient->ident);
csrc = VCC_Compile(vcc, &sb, vp->vclsrc, vp->vclsrcfile);
AZ(VSB_finish(sb));
if (VSB_len(sb))
......
......@@ -51,6 +51,25 @@ struct stevedore *stv_transient;
/*--------------------------------------------------------------------*/
int
STV__iter(struct stevedore **pp)
{
if (*pp == stv_transient) {
*pp = NULL;
return (0);
}
if (*pp != NULL)
*pp = VTAILQ_NEXT(*pp, list);
else
*pp = VTAILQ_FIRST(&stv_stevedores);
if (*pp == NULL)
*pp = stv_transient;
return (1);
}
/*--------------------------------------------------------------------*/
static void __match_proto__(cli_func_t)
stv_cli_list(struct cli *cli, const char * const *av, void *priv)
{
......
......@@ -99,19 +99,13 @@ STV_open(void)
char buf[1024];
ASSERT_CLI();
VTAILQ_FOREACH(stv, &stv_stevedores, list) {
STV_Foreach(stv) {
bprintf(buf, "storage.%s", stv->ident);
stv->vclname = strdup(buf);
AN(stv->vclname);
if (stv->open != NULL)
stv->open(stv);
}
stv = stv_transient;
bprintf(buf, "storage.%s", stv->ident);
stv->vclname = strdup(buf);
AN(stv->vclname);
if (stv->open != NULL)
stv->open(stv);
stv_next = VTAILQ_FIRST(&stv_stevedores);
}
......@@ -124,11 +118,7 @@ STV_close(void)
ASSERT_CLI();
for (i = 1; i >= 0; i--) {
/* First send close warning */
VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (stv->close != NULL)
stv->close(stv, i);
stv = stv_transient;
if (stv->close != NULL)
STV_Foreach(stv)
if (stv->close != NULL)
stv->close(stv, i);
}
......
......@@ -130,6 +130,10 @@ VTAILQ_HEAD(stevedore_head, stevedore);
extern struct stevedore_head stv_stevedores;
extern struct stevedore *stv_transient;
/*--------------------------------------------------------------------*/
#define STV_Foreach(arg) for(arg = NULL; STV__iter(&arg);)
int STV__iter(struct stevedore **);
/*--------------------------------------------------------------------*/
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
......
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