r108 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Tue Apr 4 09:29:45 CEST 2006
Author: phk
Date: 2006-04-04 09:29:45 +0200 (Tue, 04 Apr 2006)
New Revision: 108
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_httpd.c
Log:
Make the "receive a HTTP protocol header" code generic
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-04-04 07:27:06 UTC (rev 107)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-04-04 07:29:45 UTC (rev 108)
@@ -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 @@
/* 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 @@
#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 */
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-04-04 07:27:06 UTC (rev 107)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-04-04 07:29:45 UTC (rev 108)
@@ -32,43 +32,6 @@
};
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)
{
socklen_t l;
@@ -100,10 +63,7 @@
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 *
Modified: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-04-04 07:27:06 UTC (rev 107)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-04-04 07:29:45 UTC (rev 108)
@@ -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 @@
}
}
}
+
+/*--------------------------------------------------------------------*/
+
+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 */
+}
More information about the varnish-commit
mailing list