extern struct backendlist backendlist;
void VBE_DropRef(struct backend *);
void VBE_DropRefLocked(struct backend *);
-struct backend *VBE_AddBackend(struct backend_method *method, const char *ident);
+int VBE_AddBackend(struct backend_method *method, const char *ident, struct backend **be);
struct vbe_conn *VBE_NewConn(void);
void VBE_ReleaseConn(struct vbe_conn *);
void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int);
/*--------------------------------------------------------------------
* Add a backend/director instance when loading a VCL.
- * If an existing backend is matched, grab a refcount and return NULL.
- * Else create a new backend structure and return that with reference
- * initialized to one.
+ * If an existing backend is matched, grab a refcount and return one.
+ * Else create a new backend structure with reference initialized to one
+ * and return zero.
*/
-struct backend *
-VBE_AddBackend(struct backend_method *method, const char *ident)
+int
+VBE_AddBackend(struct backend_method *method, const char *ident, struct backend **be)
{
struct backend *b;
if (strcmp(b->ident, ident))
continue;
b->refcount++;
- return (NULL);
+ *be = b;
+ return (1);
}
b = calloc(sizeof *b, 1);
b->minute_limit = 1;
VTAILQ_INSERT_TAIL(&backendlist, b, list);
- return (b);
+ *be = b;
+ return (0);
}
/*--------------------------------------------------------------------*/
void
VRT_init_random_backend(struct backend **bp, const struct vrt_dir_random *t)
{
+ struct backend *b;
(void)bp;
(void)t;
+
+ if (VBE_AddBackend(&backend_method_random, t->ident, bp))
+ return; /* reuse existing backend */
+
+ b = *bp;
+ AN(t->name);
+ REPLACE(b->vcl_name, t->name);
#if 0
struct backend *b;
struct ber *ber;
#define BES_MAGIC 0x015e17ac
char *hostname;
char *portname;
- char *ident;
struct addrinfo *addr;
struct addrinfo *last_addr;
double dnsttl;
struct bes *bes;
const char *p;
- b = VBE_AddBackend(&backend_method_simple, t->ident);
- if (b == NULL)
+ if (VBE_AddBackend(&backend_method_simple, t->ident, bp))
return; /* ref to existing backend */
+ b = *bp;
+ AN(t->name);
+ REPLACE(b->vcl_name, t->name);
+
bes = calloc(sizeof *bes, 1);
XXXAN(bes);
bes->magic = BES_MAGIC;
bes->dnsttl = 300;
- AN(t->ident);
- REPLACE(bes->ident, t->ident);
-
- AN(t->name);
- REPLACE(b->vcl_name, t->name);
-
AN(t->host->portname);
REPLACE(bes->portname, t->host->portname);
if (p != NULL)
printf("Warning: could not lookup backend %s (%s:%s): %s",
b->vcl_name, bes->hostname, bes->portname, p);
-
- *bp = b;
}