struct VCL_conf *vcl;
/* Various internal stuff */
- struct event *rd_e;
struct sessmem *mem;
time_t t0;
};
/* cache_http.c */
void http_Init(struct http *ht, void *space);
-struct http *http_New(void);
-void http_Delete(struct http *hp);
int http_GetHdr(struct http *hp, const char *hdr, char **ptr);
int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr);
int http_GetReq(struct http *hp, char **b);
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
struct sessmem {
- struct sess s;
- struct event e;
+ struct sess sess;
struct iovec iov[SESS_IOVS];
int niov;
size_t liov;
+ struct http http;
+ char *http_hdr;
};
+/*--------------------------------------------------------------------*/
+
+static struct sess *
+vca_new_sess(void)
+{
+ struct sessmem *sm;
+
+ sm = calloc(
+ sizeof *sm +
+ heritage.mem_http_headers * sizeof sm->http_hdr +
+ heritage.mem_http_headerspace +
+ heritage.mem_workspace,
+ 1);
+ if (sm == NULL)
+ return (NULL);
+ VSL_stats->n_sess++;
+ sm->sess.mem = sm;
+ sm->sess.http = &sm->http;
+ http_Init(&sm->http, (void *)(sm + 1));
+ return (&sm->sess);
+}
+
+static void
+vca_delete_sess(struct sess *sp)
+{
+
+ VSL_stats->n_sess--;
+ free(sp->mem);
+}
+
+
/*--------------------------------------------------------------------
* Write data to client
* We try to use writev() if possible in order to minimize number of
accept_f(int fd, short event, void *arg)
{
socklen_t l;
- struct sessmem *sm;
struct sockaddr addr[2];
struct sess *sp;
char port[NI_MAXSERV];
VSL_stats->client_conn++;
- (void)arg;
- sm = calloc(sizeof *sm, 1);
- assert(sm != NULL); /*
- * XXX: this is probably one we should handle
- * XXX: accept, emit error NNN and close
- */
- VSL_stats->n_sess++;
+ sp = vca_new_sess();
+ assert(sp != NULL); /* XXX handle */
- sp = &sm->s;
- sp->rd_e = &sm->e;
- sp->mem = sm;
l = sizeof addr;
sp->fd = accept(fd, addr, &l);
if (sp->fd < 0) {
- free(sp);
+ vca_delete_sess(sp);
return;
}
#ifdef SO_NOSIGPIPE /* XXX Linux */
VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr);
time(&sp->t_resp);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
- sp->http = http_New();
http_RecvHead(sp->http, sp->fd, evb, vca_callback, sp);
}
VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr);
write(pipes[1], &sp, sizeof sp);
} else {
- if (sp->http != NULL)
- http_Delete(sp->http);
- VSL_stats->n_sess--;
- free(sp->mem);
+ vca_delete_sess(sp);
}
}
assert(vc != NULL); /* XXX: handle this */
VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
- hp = http_New();
+ hp = vc->http;
http_BuildSbuf(vc->fd, Build_Fetch, w->sb, sp->http);
i = write(vc->fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
if (!sp->obj->cacheable)
HSH_Deref(sp->obj);
- http_Delete(hp);
-
return (1);
}
/*--------------------------------------------------------------------*/
-struct http *
-http_New(void)
-{
- struct http *hp;
-
- hp = calloc(sizeof *hp, 1);
- assert(hp != NULL);
- VSL_stats->n_http++;
-
- hp->s = malloc(heritage.mem_http_headerspace);
- assert(hp->s != NULL);
-
- hp->e = hp->s + heritage.mem_http_headerspace;
- hp->v = hp->s;
- hp->t = hp->s;
-
- hp->hdr = malloc(sizeof *hp->hdr * heritage.mem_http_headers);
- assert(hp->hdr != NULL);
-
- return (hp);
-}
-
-void
-http_Delete(struct http *hp)
-{
-
- free(hp->hdr);
- free(hp->s);
- free(hp);
- VSL_stats->n_http--;
-}
-
-/*--------------------------------------------------------------------*/
-
int
http_GetHdr(struct http *hp, const char *hdr, char **ptr)
{
* XXX: It might be cheaper to avoid the event_engine and simply
* XXX: read(2) the header
*/
- hp = http_New();
+ hp = vc->http;
http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
event_base_loop(w->eb, 0);
http_Dissect(hp, vc->fd, 2);
MAC_STAT(n_objecthead, uint64_t, "u", "N struct objecthead");
MAC_STAT(n_header, uint64_t, "u", "N struct header");
MAC_STAT(n_smf, uint64_t, "u", "N struct smf");
-MAC_STAT(n_http, uint64_t, "u", "N struct http");
MAC_STAT(n_vbe, uint64_t, "u", "N struct vbe");
MAC_STAT(n_vbe_conn, uint64_t, "u", "N struct vbe_conn");