struct vrt_dir_random {
unsigned nmember;
- struct vrt_dir_random_entry *members;
+ const struct vrt_dir_random_entry *members;
const char *ident;
};
/* Backend related */
void VRT_init_simple_backend(struct backend **, const struct vrt_simple_backend *);
void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robin_backend *);
-void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);
+void VRT_init_random_backend(struct backend **, const struct vrt_dir_random *);
void VRT_fini_backend(struct backend *);
char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
fs = vcc_FldSpec(tl, "!host", "?port", NULL);
t_first = tl->t;
- *nbh = tl->nbackend_host++;
if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) {
ExpectErr(tl, '{');
vcc_NextToken(tl);
- Fh(tl, 0, "\nstatic const struct vrt_backend_host bh_%d = {\n",
- *nbh);
+ *nbh = tl->nbackend_host++;
+ Fh(tl, 0, "\nstatic const struct vrt_backend_host bh_%d = {\n", *nbh);
/* Check for old syntax */
if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) {
int nbh, nelem;
struct fld_spec *fs;
+ Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.backend[%d])\n",
+ PF(t_dir), tl->nbackend);
+
fs = vcc_FldSpec(tl, "!backend", "?weight", NULL);
vcc_NextToken(tl); /* ID: policy (= random) */
vcc_NextToken(tl);
}
Fc(tl, 0, "\t{ .host = 0 }\n");
- Fc(tl, 0, "}\n");
+ Fc(tl, 0, "};\n");
Fc(tl, 0,
- "\nstatic const struct vrt_dir_random vdr_%.*s[] = {\n",
+ "\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir));
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir));
vcc_EmitBeIdent(tl->fc, t_first, tl->t);
+ Fc(tl, 0, "};\n");
vcc_NextToken(tl);
+ Fi(tl, 0, "\tVRT_init_random_backend(&VGC_backend_%.*s , &vdr_%.*s);\n",
+ PF(t_dir), PF(t_dir));
+ Ff(tl, 0, "\tVRT_fini_random_backend(VGC_backend_%.*s);\n", PF(t_dir));
}
/*--------------------------------------------------------------------
vsb_cat(sb, "\n");
vsb_cat(sb, "struct vrt_dir_random {\n");
vsb_cat(sb, " unsigned nmember;\n");
- vsb_cat(sb, " struct vrt_dir_random_entry *members;\n");
+ vsb_cat(sb, " const struct vrt_dir_random_entry *members;\n");
vsb_cat(sb, " const char *ident;\n");
vsb_cat(sb, "};\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "/* Backend related */\n");
vsb_cat(sb, "void VRT_init_simple_backend(struct backend **, const struct vrt_simple_backend *);\n");
vsb_cat(sb, "void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robin_backend *);\n");
- vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);\n");
+ vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_dir_random *);\n");
vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);\n");