Commit ed77c9eb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Unify backend error handling


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1057 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 372c26c3
......@@ -297,7 +297,7 @@ void VCA_Init(void);
/* cache_backend.c */
void VBE_Init(void);
struct vbe_conn *VBE_GetFd(struct backend *bp, unsigned xid);
struct vbe_conn *VBE_GetFd(struct sess *sp);
void VBE_ClosedFd(struct vbe_conn *vc, int already);
void VBE_RecycleFd(struct vbe_conn *vc);
......@@ -367,7 +367,7 @@ int PassSession(struct sess *sp);
void PassBody(struct sess *sp);
/* cache_pipe.c */
void PipeSession(struct sess *sp);
int PipeSession(struct sess *sp);
/* cache_pool.c */
void WRK_Init(void);
......
......@@ -175,12 +175,15 @@ vbe_connect(struct backend *bp)
* new connection.
*/
struct vbe_conn *
VBE_GetFd(struct backend *bp, unsigned xid)
static struct vbe_conn *
vbe_nextfd(struct sess *sp)
{
struct vbe_conn *vc, *vc2;
struct pollfd pfd;
struct backend *bp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
bp = sp->backend;
CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
while (1) {
/*
......@@ -245,12 +248,29 @@ VBE_GetFd(struct backend *bp, unsigned xid)
if (vc != NULL ) {
assert(vc->fd >= 0);
VSL_stats->backend_conn++;
VSL(SLT_BackendXID, vc->fd, "%u", xid);
WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid);
AN(vc->backend);
}
return (vc);
}
/*--------------------------------------------------------------------*/
struct vbe_conn *
VBE_GetFd(struct sess *sp)
{
struct vbe_conn *vc;
vc = vbe_nextfd(sp);
if (vc != NULL) {
WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd,
sp->backend->vcl_name);
return (vc);
}
RES_Error(sp, 503, "Backend did not respond.");
return (NULL);
}
/* Close a connection ------------------------------------------------*/
void
......
......@@ -530,7 +530,14 @@ cnt_miss(struct sess *sp)
INCOMPL();
if (sp->handling == VCL_RET_FETCH) {
AZ(sp->vbc);
FetchHeaders(sp);
if (FetchHeaders(sp)) {
sp->obj->cacheable = 0;
HSH_Unbusy(sp->obj);
HSH_Deref(sp->obj);
sp->obj = NULL;
sp->step = STP_DONE;
return (0);
}
sp->step = STP_FETCH;
AN(sp->vbc);
return (0);
......@@ -613,7 +620,7 @@ cnt_pipe(struct sess *sp)
{
sp->wrk->acct.pipe++;
PipeSession(sp);
(void)PipeSession(sp);
sp->step = STP_DONE;
return (0);
}
......
......@@ -290,11 +290,9 @@ FetchHeaders(struct sess *sp)
sp->obj->xid = sp->xid;
vc = VBE_GetFd(sp->backend, sp->xid);
vc = VBE_GetFd(sp);
if (vc == NULL)
vc = VBE_GetFd(sp->backend, sp->xid);
XXXAN(vc);
WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
return (1);
http_ClrHeader(vc->http);
vc->http->logtag = HTTP_Tx;
......
......@@ -202,12 +202,9 @@ PassSession(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
w = sp->wrk;
vc = VBE_GetFd(sp->backend, sp->xid);
if (vc == NULL) {
RES_Error(sp, 503, "Backend did not respond.");
vc = VBE_GetFd(sp);
if (vc == NULL)
return (1);
}
WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
http_CopyReq(w, vc->fd, vc->http, sp->http);
http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PASS);
......
......@@ -40,7 +40,7 @@ rdf(struct pollfd *fds, int idx)
}
}
void
int
PipeSession(struct sess *sp)
{
struct vbe_conn *vc;
......@@ -53,12 +53,9 @@ PipeSession(struct sess *sp)
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
w = sp->wrk;
vc = VBE_GetFd(sp->backend, sp->xid);
if (vc == NULL) {
RES_Error(sp, 503, "Backend did not respond.");
return;
}
VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
vc = VBE_GetFd(sp);
if (vc == NULL)
return (1);
vc->http->logtag = HTTP_Tx;
http_CopyReq(w, vc->fd, vc->http, sp->http);
......
......@@ -103,7 +103,7 @@ RES_Error(struct sess *sp, int code, const char *expl)
vsb_cat(sb,
"Server: Varnish\r\n"
"Connection: close\r\n"
"content-Type: text/html; charset=iso-8859-1\r\n"
"Content-Type: text/html; charset=iso-8859-1\r\n"
"\r\n"
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
"<HTML>\r\n"
......
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