* $Id$
*/
+struct event_base;
+
/* cache_acceptor.c */
void *vca_main(void *arg);
void vca_retire_session(struct sess *sp);
/* 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);
#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 */
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)
{
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 *
*/
#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)
{
}
}
}
+
+/*--------------------------------------------------------------------*/
+
+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 */
+}