Commit 60be693b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the "receive a HTTP protocol header" code generic


git-svn-id: http://www.varnish-cache.org/svn/trunk@108 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 63ea99a7
......@@ -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 */
......
......@@ -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 *
......
......@@ -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 */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment