From b40c6782fe4df1888128cb96f54e2900368a2557 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 28 Sep 2007 10:29:12 +0000 Subject: [PATCH] Preparation for implementation of restarts: Move the ws from http to the containing object (session or obj). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2051 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 11 ++++++----- varnish-cache/bin/varnishd/cache_backend.c | 5 ++--- varnish-cache/bin/varnishd/cache_center.c | 2 +- varnish-cache/bin/varnishd/cache_fetch.c | 3 ++- varnish-cache/bin/varnishd/cache_http.c | 19 ++++++++++--------- varnish-cache/bin/varnishd/cache_session.c | 5 +++-- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 17f72839..c06df28e 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -117,7 +117,7 @@ struct http { unsigned magic; #define HTTP_MAGIC 0x6428b5c9 - struct ws ws[1]; + struct ws *ws; txt rx; /* Received Request */ txt pl; /* Pipelined bytes */ @@ -186,8 +186,7 @@ struct bereq { unsigned magic; #define BEREQ_MAGIC 0x3b6d250c VTAILQ_ENTRY(bereq) list; - void *space; - unsigned len; + struct ws ws[1]; struct http http[1]; }; @@ -217,6 +216,7 @@ struct object { unsigned xid; struct objhead *objhead; + struct ws ws_o[1]; unsigned char *vary; unsigned heap_idx; @@ -285,6 +285,7 @@ struct sess { /* HTTP request */ const char *doclose; struct http *http; + struct ws ws[1]; /* Timestamps, all on TIM_real() timescale */ double t_open; @@ -460,7 +461,7 @@ void http_PutResponse(struct worker *w, int fd, struct http *to, const char *res void http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...); void http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr); void http_SetH(struct http *to, unsigned n, const char *fm); -void http_Setup(struct http *ht, void *space, unsigned len); +void http_Setup(struct http *ht, struct ws *ws); int http_GetHdr(const struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char **ptr); int http_GetStatus(const struct http *hp); @@ -475,7 +476,7 @@ int http_RecvSome(int fd, struct http *hp); int http_RecvHead(struct http *hp, int fd); int http_DissectRequest(struct worker *w, struct http *sp, int fd); int http_DissectResponse(struct worker *w, struct http *sp, int fd); -void http_DoConnection(struct sess *sp); +const char *http_DoConnection(struct http *hp); void http_CopyHome(struct worker *w, int fd, struct http *hp); void http_Unset(struct http *hp, const char *hdr); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 00671bc1..c2c8f283 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -147,10 +147,9 @@ VBE_new_bereq(void) if (bereq == NULL) return (NULL); bereq->magic = BEREQ_MAGIC; - bereq->space = bereq + 1; - bereq->len = len; + WS_Init(bereq->ws, bereq + 1, len); } - http_Setup(bereq->http, bereq->space, bereq->len); + http_Setup(bereq->http, bereq->ws); return (bereq); } diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index e1dfa2d0..3ee46bae 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -763,7 +763,7 @@ cnt_recv(struct sess *sp) return (0); } - http_DoConnection(sp); + sp->doclose = http_DoConnection(sp->http); /* By default we use the first backend */ AZ(sp->backend); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 76814a17..46e26fd0 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -332,7 +332,8 @@ Fetch(struct sess *sp) CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); b = malloc(len); AN(b); - http_Setup(hp2, b, len); + WS_Init(sp->obj->ws_o, b, len); + http_Setup(hp2, sp->obj->ws_o); CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); hp2->logtag = HTTP_Obj; diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index f988011a..21bf9b97 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -160,13 +160,12 @@ http_StatusMessage(unsigned status) /*--------------------------------------------------------------------*/ void -http_Setup(struct http *hp, void *space, unsigned len) +http_Setup(struct http *hp, struct ws *ws) { - assert(len > 0); memset(hp, 0, sizeof *hp); hp->magic = HTTP_MAGIC; - WS_Init(hp->ws, space, len); + hp->ws = ws; hp->nhd = HTTP_HDR_FIRST; } @@ -266,18 +265,19 @@ http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char /*--------------------------------------------------------------------*/ -void -http_DoConnection(struct sess *sp) +const char * +http_DoConnection(struct http *hp) { - struct http *hp = sp->http; char *p, *q; + const char *ret; unsigned u; if (!http_GetHdr(hp, H_Connection, &p)) { if (strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1")) - sp->doclose = "not HTTP/1.1"; - return; + return ("not HTTP/1.1"); + return (NULL); } + ret = NULL; for (; *p; p++) { if (isspace(*p)) continue; @@ -288,7 +288,7 @@ http_DoConnection(struct sess *sp) break; u = pdiff(p, q); if (u == 5 && !strncasecmp(p, "close", u)) - sp->doclose = "Connection: close"; + ret = "Connection: close"; u = http_findhdr(hp, u, p); if (u != 0) hp->hdf[u] |= HDF_FILTER; @@ -296,6 +296,7 @@ http_DoConnection(struct sess *sp) break; p = q; } + return (ret); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_session.c b/varnish-cache/bin/varnishd/cache_session.c index 3fab3975..98e5277c 100644 --- a/varnish-cache/bin/varnishd/cache_session.c +++ b/varnish-cache/bin/varnishd/cache_session.c @@ -302,7 +302,6 @@ SES_New(const struct sockaddr *addr, unsigned len) memset(sp, 0, sizeof *sp); sp->magic = SESS_MAGIC; sp->mem = sm; - sp->http = &sm->http; sp->sockaddr = (void*)(&sm->sockaddr[0]); sp->sockaddrlen = sizeof(sm->sockaddr[0]); sp->mysockaddr = (void*)(&sm->sockaddr[1]); @@ -319,7 +318,9 @@ SES_New(const struct sockaddr *addr, unsigned len) sp->sockaddrlen = len; } - http_Setup(&sm->http, (void *)(sm + 1), sm->workspace); + WS_Init(sp->ws, (void *)(sm + 1), sm->workspace); + sp->http = &sm->http; + http_Setup(sp->http, sp->ws); return (sp); } -- 2.39.5