r431 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jul 11 18:10:10 CEST 2006


Author: phk
Date: 2006-07-11 18:10:10 +0200 (Tue, 11 Jul 2006)
New Revision: 431

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
Log:
Distribute code from FetchSession almost correctly


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 16:03:25 UTC (rev 430)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 16:10:10 UTC (rev 431)
@@ -161,6 +161,8 @@
 
 	TAILQ_ENTRY(sess)	list;
 
+	struct vbe_conn		*vbc;
+	struct http		*bkd_http;
 	struct backend		*backend;
 	struct object		*obj;
 	struct VCL_conf		*vcl;
@@ -223,7 +225,8 @@
 void EXP_TTLchange(struct object *o);
 
 /* cache_fetch.c */
-int FetchSession(struct worker *w, struct sess *sp);
+int FetchBody(struct worker *w, struct sess *sp);
+int FetchHeaders(struct worker *w, struct sess *sp);
 
 /* cache_hash.c */
 struct object *HSH_Lookup(struct worker *w, struct http *h);

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-11 16:03:25 UTC (rev 430)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-11 16:10:10 UTC (rev 431)
@@ -57,8 +57,14 @@
 DOT deliver2 -> DONE [style=bold]
  */
 
-static void cnt_deliver(struct worker *w, struct sess *sp) { (void)w; (void)sp; INCOMPL(); }
+static void
+cnt_deliver(struct worker *w, struct sess *sp)
+{
 
+	vca_write_obj(w, sp);
+	sp->step = STP_DONE;
+}
+
 /*--------------------------------------------------------------------
 DOT	DONE [
 DOT		shape=hexagon
@@ -139,8 +145,30 @@
 DOT fetch_error -> ERROR
  */
 
-static void cnt_fetch(struct worker *w, struct sess *sp) { (void)w; (void)sp; INCOMPL(); }
+static void
+cnt_fetch(struct worker *w, struct sess *sp)
+{
 
+	RFC2616_cache_policy(sp, sp->bkd_http);
+
+	VCL_fetch_method(sp);
+
+	if (sp->handling == VCL_RET_LOOKUP)
+		INCOMPL();
+	if (sp->handling == VCL_RET_PASS)
+		INCOMPL();
+	if (sp->handling == VCL_RET_INSERT_PASS)
+		INCOMPL();
+	if (sp->handling == VCL_RET_INSERT) {
+		FetchBody(w, sp);
+		sp->step = STP_DELIVER;
+		return;
+	}
+	if (sp->handling == VCL_RET_ERROR)
+		INCOMPL();
+	INCOMPL();
+}
+
 /*--------------------------------------------------------------------
 DOT subgraph cluster_hit {
 DOT	hit [
@@ -208,16 +236,14 @@
 static void
 cnt_lookup(struct worker *w, struct sess *sp)
 {
-	struct object *o;
 
-	o = HSH_Lookup(w, sp->http);
-	sp->obj = o;
-	if (o->busy) {
+	sp->obj = HSH_Lookup(w, sp->http);
+	if (sp->obj->busy) {
 		VSL_stats->cache_miss++;
 		sp->step = STP_MISS;
 	} else {
 		VSL_stats->cache_hit++;
-		VSL(SLT_Hit, sp->fd, "%u", o->xid);
+		VSL(SLT_Hit, sp->fd, "%u", sp->obj->xid);
 		sp->step = STP_HIT;
 	}
 }
@@ -269,9 +295,8 @@
 	if (sp->handling == VCL_RET_LOOKUP)
 		INCOMPL();
 	if (sp->handling == VCL_RET_FETCH) {
-		/* XXX */
-		FetchSession(w, sp);
-		sp->step = STP_DONE;
+		FetchHeaders(w, sp);
+		sp->step = STP_FETCH;
 		return;
 	}
 	INCOMPL();

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-11 16:03:25 UTC (rev 430)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-11 16:10:10 UTC (rev 431)
@@ -229,8 +229,9 @@
 }
 
 /*--------------------------------------------------------------------*/
+
 int
-FetchSession(struct worker *w, struct sess *sp)
+FetchBody(struct worker *w, struct sess *sp)
 {
 	int i, cls;
 	struct vbe_conn *vc;
@@ -238,38 +239,9 @@
 	char *b;
 	int body;
 
-	sp->obj->xid = sp->xid;
+	vc = sp->vbc;
+	hp = sp->bkd_http;
 
-	vc = VBE_GetFd(sp->backend, sp->xid);
-	if (vc == NULL)
-		vc = VBE_GetFd(sp->backend, sp->xid);
-	assert(vc != NULL);	/* XXX: handle this */
-	VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
-
-	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));
-	time(&sp->t_req);
-
-	/* XXX: copy any contents */
-
-	/*
-	 * XXX: It might be cheaper to avoid the event_engine and simply
-	 * XXX: read(2) the header
-	 */
-	http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
-	event_base_loop(w->eb, 0);
-	time(&sp->t_resp);
-	assert(http_DissectResponse(hp, vc->fd) == 0);
-
-	body = RFC2616_cache_policy(sp, hp);
-
-	VCL_fetch_method(sp);
-
-	if (sp->obj->cacheable)
-		EXP_Insert(sp->obj);
-
 	http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp);
 	if (body) {
 		if (http_GetHdr(hp, "Content-Length", &b))
@@ -285,8 +257,6 @@
 	sp->obj->header = strdup(sbuf_data(w->sb));
 	VSL_stats->n_header++;
 
-	vca_write_obj(w, sp);
-
 	if (http_GetHdr(hp, "Connection", &b) && !strcasecmp(b, "close"))
 		cls = 1;
 
@@ -295,9 +265,50 @@
 	else
 		VBE_RecycleFd(vc);
 
+	if (sp->obj->cacheable)
+		EXP_Insert(sp->obj);
 	HSH_Unbusy(sp->obj);
 	if (!sp->obj->cacheable)
 		HSH_Deref(sp->obj);
+	return (0);
+}
 
-	return (1);
+/*--------------------------------------------------------------------*/
+
+int
+FetchHeaders(struct worker *w, struct sess *sp)
+{
+	int i, cls;
+	struct vbe_conn *vc;
+	struct http *hp;
+	char *b;
+	int body;
+
+	sp->obj->xid = sp->xid;
+
+	vc = VBE_GetFd(sp->backend, sp->xid);
+	if (vc == NULL)
+		vc = VBE_GetFd(sp->backend, sp->xid);
+	assert(vc != NULL);	/* XXX: handle this */
+	VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
+
+	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));
+	time(&sp->t_req);
+
+	/* XXX: copy any body ?? */
+
+	/*
+	 * XXX: It might be cheaper to avoid the event_engine and simply
+	 * XXX: read(2) the header
+	 */
+	http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
+	event_base_loop(w->eb, 0);
+	time(&sp->t_resp);
+	assert(http_DissectResponse(hp, vc->fd) == 0);
+	sp->vbc = vc;
+	sp->bkd_http = hp;
+	return (0);
 }




More information about the varnish-commit mailing list