]> err.no Git - varnish/commitdiff
Make the "receive a HTTP protocol header" code generic
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 07:29:45 +0000 (07:29 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 07:29:45 +0000 (07:29 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@108 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_httpd.c

index 3a041bc3e79b163b69d79993e8acc075d08fa5bf..d4bdf282e909edb732db5c695ad6f9a1341563d1 100644 (file)
@@ -2,6 +2,8 @@
  * $Id$
  */
 
+struct event_base;
+
 /* cache_acceptor.c */
 void *vca_main(void *arg);
 void vca_retire_session(struct sess *sp);
@@ -14,10 +16,14 @@ void VBE_ClosedFd(void *ptr);
 
 /* cache_httpd.c */
 void HttpdAnalyze(struct sess *sp);
+void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func);
 
 /* cache_main.c */
 pthread_mutex_t        sessmtx;
 
+/* cache_pass.c */
+void PassSession(struct sess *sp);
+
 /* cache_pipe.c */
 void PipeSession(struct sess *sp);
 
@@ -30,6 +36,7 @@ void VSL_Init(void);
 #ifdef SHMLOGHEAD_MAGIC
 void VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e);
 void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...);
+#define HERE() VSL(SLT_Debug, 0, "%s(%d)", __func__, __LINE__)
 #endif
 
 /* cache_vcl.c */
index c613b405ba66b05572b525836ffa91ae76ad9273..b6857322b907e74997f13e55357774e6b7de6bbc 100644 (file)
@@ -31,43 +31,6 @@ struct sessmem {
        struct event    e;
 };
 
-static void
-http_read_f(int fd, short event, void *arg)
-{
-       struct sess *sp = arg;
-       const char *p;
-       int i;
-
-       assert(VCA_RXBUFSIZE - sp->rcv_len > 0);
-       i = read(fd, sp->rcv + sp->rcv_len, VCA_RXBUFSIZE - sp->rcv_len);
-       if (i <= 0) {
-               VSL(SLT_SessionClose, sp->fd, "remote %d", sp->rcv_len);
-               event_del(sp->rd_e);
-               close(sp->fd);
-               free(sp->mem);
-               return;
-       }
-
-       sp->rcv_len += i;
-       sp->rcv[sp->rcv_len] = '\0';
-
-       p = sp->rcv;
-       while (1) {
-               /* XXX: we could save location of all linebreaks for later */
-               p = strchr(p, '\n');
-               if (p == NULL)
-                       return;
-               p++;
-               if (*p == '\r')
-                       p++;
-               if (*p != '\n')
-                       continue;
-               break;
-       }
-       event_del(sp->rd_e);
-       DealWithSession(sp);
-}
-
 static void
 accept_f(int fd, short event, void *arg)
 {
@@ -100,10 +63,7 @@ accept_f(int fd, short event, void *arg)
        strlcat(sp->addr, ":", VCA_ADDRBUFSIZE);
        strlcat(sp->addr, port, VCA_ADDRBUFSIZE);
        VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr);
-       event_set(sp->rd_e, sp->fd, EV_READ | EV_PERSIST,
-           http_read_f, sp);
-       event_base_set(evb, sp->rd_e);
-       event_add(sp->rd_e, NULL);      /* XXX: timeout */
+       HttpdGetHead(sp, evb, DealWithSession);
 }
 
 void *
index 0694c913e98bb5340b1816e316fb606a7d763f6b..d8852093670b61f970f7232db9f9021a00ea3778 100644 (file)
@@ -5,15 +5,21 @@
  */
 
 #include <stdio.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
 #include <ctype.h>
+#include <event.h>
 
 #include "libvarnish.h"
 #include "shmlog.h"
 #include "vcl_lang.h"
 #include "cache.h"
 
+/*--------------------------------------------------------------------*/
+
 void
 HttpdAnalyze(struct sess *sp)
 {
@@ -87,3 +93,55 @@ HttpdAnalyze(struct sess *sp)
                }
        }
 }
+
+/*--------------------------------------------------------------------*/
+
+static void
+http_read_f(int fd, short event, void *arg)
+{
+       struct sess *sp = arg;
+       const char *p;
+       int i;
+
+       assert(VCA_RXBUFSIZE - sp->rcv_len > 0);
+       i = read(fd, sp->rcv + sp->rcv_len, VCA_RXBUFSIZE - sp->rcv_len);
+       if (i <= 0) {
+               VSL(SLT_SessionClose, sp->fd, "remote %d", sp->rcv_len);
+               event_del(sp->rd_e);
+               close(sp->fd);
+               free(sp->mem);
+               return;
+       }
+
+       sp->rcv_len += i;
+       sp->rcv[sp->rcv_len] = '\0';
+
+       p = sp->rcv;
+       while (1) {
+               /* XXX: we could save location of all linebreaks for later */
+               p = strchr(p, '\n');
+               if (p == NULL)
+                       return;
+               p++;
+               if (*p == '\r')
+                       p++;
+               if (*p != '\n')
+                       continue;
+               break;
+       }
+       event_del(sp->rd_e);
+       sp->sesscb(sp);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func)
+{
+
+       sp->sesscb = func;
+       assert(sp->rd_e != NULL);
+       event_set(sp->rd_e, sp->fd, EV_READ | EV_PERSIST, http_read_f, sp);
+        event_base_set(eb, sp->rd_e);
+        event_add(sp->rd_e, NULL);      /* XXX: timeout */
+}