varnishd_SOURCES = \
cache_acceptor.c \
+ cache_backend.c \
cache_httpd.c \
cache_main.c \
cache_pool.c \
/* cache_acceptor.c */
void *vca_main(void *arg);
+/* cache_backend.c */
+void VBE_Init(void);
+
/* cache_httpd.c */
void HttpdAnalyze(struct sess *sp);
--- /dev/null
+/*
+ * $Id$
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+#include "libvarnish.h"
+#include "vcl_lang.h"
+
+/*
+ * The internal backend structure for managing connection pools per
+ * backend. We need to shadow the backend stucture from the VCL
+ * in order let connections live across VCL switches.
+ */
+
+struct vbe_conn {
+ TAILQ_ENTRY(vbe_conn) list;
+ struct vbe *vbe;
+ int fd;
+};
+
+struct vbe {
+ unsigned ip;
+ TAILQ_ENTRY(vbe) list;
+ TAILQ_HEAD(,vbe_conn) fconn;
+ TAILQ_HEAD(,vbe_conn) bconn;
+ unsigned nconn;
+};
+
+static TAILQ_HEAD(,vbe) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head);
+
+static pthread_mutex_t vbemtx;
+
+/*--------------------------------------------------------------------*/
+void
+connect_to_backend(struct vbe_conn *vc, struct backend *bp)
+{
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VBE_GetFd(struct backend *bp)
+{
+ struct vbe *vp;
+ struct vbe_conn *vc;
+
+ AZ(pthread_mutex_lock(&vbemtx));
+ vp = bp->vbe;
+ if (vp == NULL) {
+ TAILQ_FOREACH(vp, &vbe_head, list)
+ if (vp->ip == bp->ip)
+ break;
+ }
+ if (vp == NULL) {
+ vp = calloc(sizeof *vp, 1);
+ assert(vp != NULL);
+ TAILQ_INIT(&vp->fconn);
+ TAILQ_INIT(&vp->bconn);
+ vp->ip = bp->ip;
+ bp->vbe = vp;
+ TAILQ_INSERT_TAIL(&vbe_head, vp, list);
+ }
+ /* XXX: check nconn vs backend->maxcon */
+ vc = TAILQ_FIRST(&vp->fconn);
+ if (vc != NULL) {
+ TAILQ_REMOVE(&vp->fconn, vc, list);
+ TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
+ AZ(pthread_mutex_unlock(&vbemtx));
+ return (vc->fd);
+ }
+ vc = calloc(sizeof *vc, 1);
+ assert(vc != NULL);
+ vc->vbe = vp;
+ TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
+ AZ(pthread_mutex_unlock(&vbemtx));
+ connect_to_backend(vc, bp);
+
+ /* XXX */
+ return (-1);
+}
+
+
+
+
+void
+VBE_Init(void)
+{
+
+ AZ(pthread_mutex_init(&vbemtx, NULL));
+}
printf("Child starts\n");
AZ(pthread_mutex_init(&sessmtx, NULL));
+ VBE_Init();
VSL_Init();
CacheInitPool();
HttpdAnalyze(sp);
+ sp->backend = sp->vcl->default_backend;
/* Call the VCL program */
sp->vcl->main_func(sp);
buf = NULL;
asprintf(&buf,
- "backend default { set backend.ip = %s; }\n"
+ "backend default { set backend.host = \"%s\"; }\n"
"sub main {\n"
" pass;\n"
#if 0
TAILQ_ENTRY(sess) list;
+ struct backend *backend;
struct VCL_conf *vcl;
/* Various internal stuff */
struct sessmem *mem;
};
-struct be_conn {
- TAILQ_ENTRY(be_conn) list;
- int fd;
-};
-
struct backend {
+ const char *hostname;
+ const char *portname;
+ struct addrinfo *addr;
unsigned ip;
double responsetime;
double timeout;
double bandwidth;
int down;
- /* Internals */
- TAILQ_HEAD(,be_conn) bec_head;
- unsigned nbec;
+ /* internal stuff */
+ struct vbe *vbe;
};
#define VCL_FARGS struct sess *sess
static struct var vars[] = {
+ { "backend.host", STRING, 0, "backend->hostname" },
+ { "backend.port", STRING, 0, "backend->portname" },
+#if 0
{ "req.ttlfactor", FLOAT, 0, "req->ttlfactor" },
{ "req.url.host", STRING, 0, "req->url.host" },
{ "req.url.path", STRING, 0, "req->url.path" },
{ "req.backend", BACKEND, 0, "req->backend" },
{ "client.ip", IP, 0, "client->ip" },
{ "backend.response_time", TIME, 0, "backend->responsetime" },
- { "backend.ip", IP, 0, "backend->ip" },
{ "backend.down", BOOL, 0, "backend->down" },
{ "backend.timeout", TIME, 0, "backend->timeout" },
{ "backend.bandwidth", RATE, 0, "backend->bandwidth" },
{ "obj.result", INT, 0, "obj->result" },
{ "obj.size", SIZE, 0, "obj->size" },
{ "obj.usage", INT, 0, "obj->usage" },
+#endif
{ NULL, INT, 0, "NULL" }
};
fputs("\n", f);
fputs(" TAILQ_ENTRY(sess) list;\n", f);
fputs("\n", f);
+ fputs(" struct backend *backend;\n", f);
fputs(" struct VCL_conf *vcl;\n", f);
fputs("\n", f);
fputs(" /* Various internal stuff */\n", f);
fputs(" struct sessmem *mem;\n", f);
fputs("};\n", f);
fputs("\n", f);
- fputs("struct be_conn {\n", f);
- fputs(" TAILQ_ENTRY(be_conn) list;\n", f);
- fputs(" int fd;\n", f);
- fputs("};\n", f);
- fputs("\n", f);
fputs("struct backend {\n", f);
+ fputs(" const char *hostname;\n", f);
+ fputs(" const char *portname;\n", f);
+ fputs(" struct addrinfo *addr;\n", f);
fputs(" unsigned ip;\n", f);
fputs(" double responsetime;\n", f);
fputs(" double timeout;\n", f);
fputs(" double bandwidth;\n", f);
fputs(" int down;\n", f);
fputs("\n", f);
- fputs(" /* Internals */\n", f);
- fputs(" TAILQ_HEAD(,be_conn) bec_head;\n", f);
- fputs(" unsigned nbec;\n", f);
+ fputs(" /* internal stuff */\n", f);
+ fputs(" struct vbe *vbe;\n", f);
fputs("};\n", f);
fputs("\n", f);
fputs("#define VCL_FARGS struct sess *sess\n", f);