#include <sys/ioctl.h>
#include "libvarnish.h"
+#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
+struct vbc_mem {
+ struct vbe_conn vbe;
+ struct http http;
+ char *http_hdr;
+};
+
/* A backend IP */
struct vbe {
static struct event_base *vbe_evb;
static int vbe_pipe[2];
+/*--------------------------------------------------------------------*/
+
+static struct vbe_conn *
+vbe_new_conn(void)
+{
+ struct vbc_mem *vbcm;
+
+ vbcm = calloc(
+ sizeof *vbcm +
+ heritage.mem_http_headers * sizeof vbcm->http_hdr +
+ heritage.mem_http_headerspace +
+ heritage.mem_workspace,
+ 1);
+ if (vbcm == NULL)
+ return (NULL);
+ VSL_stats->n_vbe_conn++;
+ vbcm->vbe.vbcm = vbcm;
+ vbcm->vbe.http = &vbcm->http;
+ http_Init(&vbcm->http, (void *)(vbcm + 1));
+ return (&vbcm->vbe);
+}
+
+static void
+vbe_delete_conn(struct vbe_conn *vb)
+{
+
+ VSL_stats->n_vbe_conn--;
+ free(vb->vbcm);
+}
+
/*--------------------------------------------------------------------
* XXX: we should not call getaddrinfo() every time, we should cache
* and apply round-robin with blacklisting of entries that do not respond
TAILQ_REMOVE(&vc->vbe->bconn, vc, list);
if (vc->fd < 0) {
vc->vbe->nconn--;
- free(vc);
- VSL_stats->n_vbe_conn--;
+ vbe_delete_conn(vc);
} else {
vc->inuse = 0;
event_add(&vc->ev, NULL);
AZ(pthread_mutex_unlock(&vbemtx));
event_del(&vc->ev);
close(vc->fd);
- free(vc);
- VSL_stats->n_vbe_conn--;
+ vbe_delete_conn(vc);
}
/* Backend monitoring thread -----------------------------------------*/
if (vp == NULL) {
vp = calloc(sizeof *vp, 1);
assert(vp != NULL);
- VSL_stats->n_vbe++;
TAILQ_INIT(&vp->fconn);
TAILQ_INIT(&vp->bconn);
vp->ip = bp->ip;
TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
AZ(pthread_mutex_unlock(&vbemtx));
} else {
- vc = calloc(sizeof *vc, 1);
- VSL_stats->n_vbe_conn++;
- assert(vc != NULL);
+ vc = vbe_new_conn();
+ if (vc == NULL) {
+ AZ(pthread_mutex_unlock(&vbemtx));
+ return (NULL);
+ }
+ vp->nconn++;
vc->vbe = vp;
vc->fd = -1;
vc->inuse = 1;
TAILQ_INSERT_TAIL(&vp->bconn, vc, list);
- vp->nconn++;
AZ(pthread_mutex_unlock(&vbemtx));
connect_to_backend(vc, bp);
if (vc->fd < 0) {
TAILQ_REMOVE(&vc->vbe->bconn, vc, list);
vp->nconn--;
AZ(pthread_mutex_unlock(&vbemtx));
- free(vc);
- vc = NULL;
- } else {
- VSL_stats->backend_conn++;
- event_set(&vc->ev, vc->fd, EV_READ | EV_PERSIST, vbe_rdf, vc);
- event_base_set(vbe_evb, &vc->ev);
+ vbe_delete_conn(vc);
+ return (NULL);
}
+ VSL_stats->backend_conn++;
+ event_set(&vc->ev, vc->fd,
+ EV_READ | EV_PERSIST, vbe_rdf, vc);
+ event_base_set(vbe_evb, &vc->ev);
}
- if (vc != NULL)
- VSL(SLT_BackendXID, vc->fd, "%u", xid);
+ VSL(SLT_BackendXID, vc->fd, "%u", xid);
return (vc);
}
#include "libvarnish.h"
#include "shmlog.h"
+#include "heritage.h"
#include "cache.h"
-static unsigned http_bufsize = 4096;
-static unsigned http_nhdr = 128;
+/*--------------------------------------------------------------------*/
+
+void
+http_Init(struct http *hp, void *space)
+{
+ char *sp = space;
+
+ memset(hp, 0, sizeof *hp);
+ hp->hdr = (void *)sp;
+ sp += heritage.mem_http_headers * sizeof hp->hdr;
+ hp->s = sp;
+ hp->e = hp->s + heritage.mem_http_headerspace;
+}
/*--------------------------------------------------------------------*/
assert(hp != NULL);
VSL_stats->n_http++;
- hp->s = malloc(http_bufsize);
+ hp->s = malloc(heritage.mem_http_headerspace);
assert(hp->s != NULL);
- hp->e = hp->s + http_bufsize;
+ hp->e = hp->s + heritage.mem_http_headerspace;
hp->v = hp->s;
hp->t = hp->s;
- hp->hdr = malloc(sizeof *hp->hdr * http_nhdr);
+ hp->hdr = malloc(sizeof *hp->hdr * heritage.mem_http_headers);
assert(hp->hdr != NULL);
return (hp);
if (p == q)
break;
- if (hp->nhdr < http_nhdr) {
+ if (hp->nhdr < heritage.mem_http_headers) {
hp->hdr[hp->nhdr++] = p;
VSLR(SLT_Header, fd, p, q);
} else {