]> err.no Git - varnish/commitdiff
Start centralizing the flow of requests through varnish so we get
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 12:31:44 +0000 (12:31 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 12:31:44 +0000 (12:31 +0000)
one source file with the highest level of policy.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@426 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c [new file with mode: 0644]
varnish-cache/bin/varnishd/cache_pool.c

index c26387171cae93ff38ff9e9a1da3d5630c67efae..3e24cc3195e05f8604282cd64d84f53e4ebfe3e8 100644 (file)
@@ -17,6 +17,7 @@ varnishd_SOURCES = \
        cache_acceptor.c \
        cache_backend.c \
        cache_ban.c \
+       cache_center.c \
        cache_expire.c \
        cache_fetch.c \
        cache_hash.c \
index cd3b5ac632e4f9e7d2da087717587cf3a31c0b23..8ab94f6793b749c0a71929e1667a04ce7375827c 100644 (file)
@@ -205,6 +205,9 @@ void cli_func_url_purge(struct cli *cli, char **av, void *priv);
 void BAN_NewObj(struct object *o);
 int BAN_CheckObject(struct object *o, const char *url);
 
+/* cache_center.c [CNT] */
+void CNT_Session(struct worker *w, struct sess *sp);
+
 /* cache_expiry.c */
 void EXP_Insert(struct object *o);
 void EXP_Init(void);
diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c
new file mode 100644 (file)
index 0000000..fdf9564
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sbuf.h>
+
+#include "libvarnish.h"
+#include "heritage.h"
+#include "shmlog.h"
+#include "vcl.h"
+#include "cache.h"
+
+/*--------------------------------------------------------------------*/
+
+static int
+LookupSession(struct worker *w, struct sess *sp)
+{
+       struct object *o;
+
+       o = HSH_Lookup(w, sp->http);
+       sp->obj = o;
+       if (o->busy) {
+               VSL_stats->cache_miss++;
+               VCL_miss_method(sp);
+       } else {
+               VSL_stats->cache_hit++;
+               VSL(SLT_Hit, sp->fd, "%u", o->xid);
+               VCL_hit_method(sp);
+       }
+       return (0);
+}
+
+static int
+DeliverSession(struct worker *w, struct sess *sp)
+{
+
+
+       vca_write_obj(w, sp);
+       HSH_Deref(sp->obj);
+       sp->obj = NULL;
+       return (1);
+}
+
+void
+CNT_Session(struct worker *w, struct sess *sp)
+{
+       int done;
+       char *b;
+
+       time(&sp->t0);
+       AZ(pthread_mutex_lock(&sessmtx));
+       sp->vcl = GetVCL();
+       AZ(pthread_mutex_unlock(&sessmtx));
+
+       done = http_DissectRequest(sp->http, sp->fd);
+       if (done != 0) {
+               RES_Error(w, sp, done, NULL);
+               goto out;
+       }
+
+       sp->backend = sp->vcl->backend[0];
+
+       VCL_recv_method(sp);
+
+       for (done = 0; !done; ) {
+               switch(sp->handling) {
+               case VCL_RET_LOOKUP:
+                       done = LookupSession(w, sp);
+                       break;
+               case VCL_RET_FETCH:
+                       done = FetchSession(w, sp);
+                       break;
+               case VCL_RET_DELIVER:
+                       done = DeliverSession(w, sp);
+                       break;
+               case VCL_RET_PIPE:
+                       PipeSession(w, sp);
+                       done = 1;
+                       break;
+               case VCL_RET_PASS:
+                       PassSession(w, sp);
+                       done = 1;
+                       break;
+               default:
+                       INCOMPL();
+               }
+       }
+       if (http_GetHdr(sp->http, "Connection", &b) &&
+           !strcmp(b, "close")) {
+               vca_close_session(sp, "Connection header");
+       } else if (http_GetProto(sp->http, &b) &&
+           strcmp(b, "HTTP/1.1")) {
+               vca_close_session(sp, "not HTTP/1.1");
+       }
+
+out:
+       AZ(pthread_mutex_lock(&sessmtx));
+       RelVCL(sp->vcl);
+       AZ(pthread_mutex_unlock(&sessmtx));
+       sp->vcl = NULL;
+       vca_return_session(sp);
+}
index d4663777408c4dd3efca0d989739018d11aea4c9..f7f466f2120d51ac9bbfb8b924ac4d502c101a2d 100644 (file)
@@ -28,97 +28,6 @@ static TAILQ_HEAD(, workreq) wrk_reqhead = TAILQ_HEAD_INITIALIZER(wrk_reqhead);
 
 /*--------------------------------------------------------------------*/
 
-static int
-LookupSession(struct worker *w, struct sess *sp)
-{
-       struct object *o;
-
-       o = HSH_Lookup(w, sp->http);
-       sp->obj = o;
-       if (o->busy) {
-               VSL_stats->cache_miss++;
-               VCL_miss_method(sp);
-       } else {
-               VSL_stats->cache_hit++;
-               VSL(SLT_Hit, sp->fd, "%u", o->xid);
-               VCL_hit_method(sp);
-       }
-       return (0);
-}
-
-static int
-DeliverSession(struct worker *w, struct sess *sp)
-{
-
-
-       vca_write_obj(w, sp);
-       HSH_Deref(sp->obj);
-       sp->obj = NULL;
-       return (1);
-}
-
-static void
-wrk_WorkSession(struct worker *w, struct sess *sp)
-{
-       int done;
-       char *b;
-
-       time(&sp->t0);
-       AZ(pthread_mutex_lock(&sessmtx));
-       sp->vcl = GetVCL();
-       AZ(pthread_mutex_unlock(&sessmtx));
-
-       done = http_DissectRequest(sp->http, sp->fd);
-       if (done != 0) {
-               RES_Error(w, sp, done, NULL);
-               goto out;
-       }
-
-       sp->backend = sp->vcl->backend[0];
-
-       VCL_recv_method(sp);
-
-       for (done = 0; !done; ) {
-               switch(sp->handling) {
-               case VCL_RET_LOOKUP:
-                       done = LookupSession(w, sp);
-                       break;
-               case VCL_RET_FETCH:
-                       done = FetchSession(w, sp);
-                       break;
-               case VCL_RET_DELIVER:
-                       done = DeliverSession(w, sp);
-                       break;
-               case VCL_RET_PIPE:
-                       PipeSession(w, sp);
-                       done = 1;
-                       break;
-               case VCL_RET_PASS:
-                       PassSession(w, sp);
-                       done = 1;
-                       break;
-               default:
-                       INCOMPL();
-               }
-       }
-       if (http_GetHdr(sp->http, "Connection", &b) &&
-           !strcmp(b, "close")) {
-               vca_close_session(sp, "Connection header");
-       } else if (http_GetProto(sp->http, &b) &&
-           strcmp(b, "HTTP/1.1")) {
-               vca_close_session(sp, "not HTTP/1.1");
-       }
-
-out:
-       AZ(pthread_mutex_lock(&sessmtx));
-       RelVCL(sp->vcl);
-       AZ(pthread_mutex_unlock(&sessmtx));
-       sp->vcl = NULL;
-       vca_return_session(sp);
-}
-
-/*--------------------------------------------------------------------*/
-
 static void *
 wrk_thread(void *priv)
 {
@@ -154,7 +63,7 @@ wrk_thread(void *priv)
                        TAILQ_REMOVE(&wrk_reqhead, wrq, list);
                        AZ(pthread_mutex_unlock(&wrk_mtx));
                        assert(wrq->sess != NULL);
-                       wrk_WorkSession(w, wrq->sess);
+                       CNT_Session(w, wrq->sess);
                        AZ(pthread_mutex_lock(&wrk_mtx));
                        VSL_stats->n_wrk_busy--;
                        TAILQ_INSERT_HEAD(&wrk_head, w, list);