From ec250dfdc546929cb74cf44f828058abdfc37984 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Fri, 15 Jan 1999 13:11:42 +0000 Subject: [PATCH] only call errorAppendEntry in one spot --- src/forward.cc | 44 +++++++++++++++++++++----------------------- src/gopher.cc | 3 ++- src/helper.cc | 2 +- src/http.cc | 16 +++++++++++----- src/protos.h | 4 ++-- src/structs.h | 8 ++------ src/wais.cc | 3 ++- src/whois.cc | 7 +++++-- 8 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/forward.cc b/src/forward.cc index a59a033b57..28d2c94e79 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $Id: forward.cc,v 1.45 1999/01/13 21:59:52 wessels Exp $ + * $Id: forward.cc,v 1.46 1999/01/15 06:11:42 wessels Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -75,7 +75,6 @@ static void fwdStateFree(FwdState * fwdState) { StoreEntry *e = fwdState->entry; - ErrorState *err; int sfd; static int loop_detect = 0; debug(17, 3) ("fwdStateFree: %p\n", fwdState); @@ -83,11 +82,8 @@ fwdStateFree(FwdState * fwdState) assert(e->mem_obj); if (e->store_status == STORE_PENDING) { if (e->mem_obj->inmem_hi == 0) { - assert(fwdState->fail.err_code); - err = errorCon(fwdState->fail.err_code, fwdState->fail.http_code); - err->request = requestLink(fwdState->request); - err->xerrno = fwdState->fail.xerrno; - errorAppendEntry(e, err); + assert(fwdState->err); + errorAppendEntry(e, fwdState->err); } } fwdServersFree(&fwdState->servers); @@ -128,7 +124,7 @@ static void fwdServerClosed(int fd, void *data) { FwdState *fwdState = data; - debug(17, 3) ("fwdServerClosed: FD %d %s\n", fd, storeUrl(fwdState->entry)); + debug(17, 2) ("fwdServerClosed: FD %d %s\n", fd, storeUrl(fwdState->entry)); assert(fwdState->server_fd == fd); fwdState->server_fd = -1; if (fwdCheckRetry(fwdState)) { @@ -155,7 +151,7 @@ fwdConnectDone(int server_fd, int status, void *data) err = errorCon(ERR_DNS_FAIL, HTTP_SERVICE_UNAVAILABLE); err->dnsserver_msg = xstrdup(dns_error_message); err->request = requestLink(request); - errorAppendEntry(fwdState->entry, err); + fwdFail(fwdState, err); comm_close(server_fd); } else if (status != COMM_OK) { assert(fs); @@ -169,7 +165,7 @@ fwdConnectDone(int server_fd, int status, void *data) err->port = request->port; } err->request = requestLink(request); - errorAppendEntry(fwdState->entry, err); + fwdFail(fwdState, err); if (fs->peer) peerCheckConnectStart(fs->peer); comm_close(server_fd); @@ -186,13 +182,13 @@ fwdConnectTimeout(int fd, void *data) FwdState *fwdState = data; StoreEntry *entry = fwdState->entry; ErrorState *err; - debug(17, 3) ("fwdConnectTimeout: FD %d: '%s'\n", fd, storeUrl(entry)); + debug(17, 2) ("fwdConnectTimeout: FD %d: '%s'\n", fd, storeUrl(entry)); assert(fd == fwdState->server_fd); if (entry->mem_obj->inmem_hi == 0) { err = errorCon(ERR_CONNECT_FAIL, HTTP_GATEWAY_TIMEOUT); err->request = requestLink(fwdState->request); - err->xerrno = ETIMEDOUT; /* cheat */ - errorAppendEntry(entry, err); + err->xerrno = ETIMEDOUT; + fwdFail(fwdState, err); } comm_close(fd); } @@ -236,7 +232,7 @@ fwdConnectStart(FwdState * fwdState) err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; err->request = requestLink(fwdState->request); - errorAppendEntry(fwdState->entry, err); + fwdFail(fwdState, err); fwdStateFree(fwdState); return; } @@ -268,7 +264,8 @@ fwdStartFail(FwdState * fwdState) ErrorState *err; err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE); err->request = requestLink(fwdState->request); - errorAppendEntry(fwdState->entry, err); + err->xerrno = errno; + fwdFail(fwdState, err); fwdStateFree(fwdState); } @@ -321,7 +318,7 @@ fwdDispatch(FwdState * fwdState) default: debug(17, 1) ("fwdDispatch: Cannot retrieve '%s'\n", storeUrl(entry)); - fwdFail(fwdState, ERR_UNSUP_REQ, HTTP_BAD_REQUEST, -1); + fwdFail(fwdState, errorCon(ERR_UNSUP_REQ, HTTP_BAD_REQUEST)); comm_close(fwdState->server_fd); break; } @@ -432,6 +429,7 @@ fwdStart(int fd, StoreEntry * e, request_t * r, struct in_addr client_addr) fwdState->request = requestLink(r); fwdState->start = squid_curtime; storeLockObject(e); + EBIT_SET(e->flags, ENTRY_FWD_HDR_WAIT); storeRegisterAbort(e, fwdAbort, fwdState); peerSelect(r, e, fwdStartComplete, fwdState); } @@ -453,16 +451,16 @@ fwdCheckDeferRead(int fdnotused, void *data) } void -fwdFail(FwdState * fwdState, int err_code, http_status http_code, int xerrno) +fwdFail(FwdState * fwdState, ErrorState *errorState) { assert(EBIT_TEST(fwdState->entry->flags, ENTRY_FWD_HDR_WAIT)); debug(17, 3) ("fwdFail: %s \"%s\"\n\t%s\n", - err_type_str[err_code], - httpStatusString(http_code), + err_type_str[errorState->type], + httpStatusString(errorState->http_status), storeUrl(fwdState->entry)); - fwdState->fail.err_code = err_code; - fwdState->fail.http_code = http_code; - fwdState->fail.xerrno = xerrno; + if (fwdState->err) + errorStateFree(fwdState->err); + fwdState->err = errorState; } /* @@ -472,7 +470,7 @@ void fwdAbort(void *data) { FwdState *fwdState = data; - debug(17, 3) ("fwdAbort: %s\n", storeUrl(fwdState->entry)); + debug(17, 2) ("fwdAbort: %s\n", storeUrl(fwdState->entry)); fwdStateFree(fwdState); } diff --git a/src/gopher.cc b/src/gopher.cc index 8c6b7053e8..19185975fd 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,7 +1,7 @@ /* - * $Id: gopher.cc,v 1.144 1999/01/12 23:37:45 wessels Exp $ + * $Id: gopher.cc,v 1.145 1999/01/15 06:11:43 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -187,6 +187,7 @@ gopherMimeCreate(GopherStateData * gopherState) break; } memBufPrintf(&mb, "\r\n"); + EBIT_CLR(gopherState->entry->flags, ENTRY_FWD_HDR_WAIT); storeAppend(gopherState->entry, mb.buf, mb.size); memBufClean(&mb); } diff --git a/src/helper.cc b/src/helper.cc index 82f784af7a..87bb353c9a 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -177,7 +177,7 @@ helperShutdown(helper * hlp) continue; } srv->flags.closing = 1; - comm_close(srv->wfd); + comm_close(srv->rfd); } } diff --git a/src/http.cc b/src/http.cc index e30920a1e8..1eb591b132 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.339 1999/01/13 05:54:48 wessels Exp $ + * $Id: http.cc,v 1.340 1999/01/15 06:11:44 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -92,7 +92,8 @@ httpTimeout(int fd, void *data) debug(11, 4) ("httpTimeout: FD %d: '%s'\n", fd, storeUrl(entry)); assert(entry->store_status == STORE_PENDING); if (entry->mem_obj->inmem_hi == 0) { - fwdFail(httpState->fwd, ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, 0); + fwdFail(httpState->fwd, + errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT)); } comm_close(fd); } @@ -468,13 +469,19 @@ httpReadReply(int fd, void *data) if (ignoreErrno(errno)) { commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); } else if (entry->mem_obj->inmem_hi == 0) { - fwdFail(httpState->fwd, ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, errno); + ErrorState *err; + err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); + err->xerrno = errno; + fwdFail(httpState->fwd, err); comm_close(fd); } else { comm_close(fd); } } else if (len == 0 && entry->mem_obj->inmem_hi == 0) { - fwdFail(httpState->fwd, ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE, errno); + ErrorState *err; + err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE); + err->xerrno = errno; + fwdFail(httpState->fwd, err); httpState->eof = 1; comm_close(fd); } else if (len == 0) { @@ -824,7 +831,6 @@ httpStart(FwdState * fwd) httpState->fwd = fwd; httpState->entry = fwd->entry; httpState->fd = fd; - EBIT_SET(httpState->entry->flags, ENTRY_FWD_HDR_WAIT); if (fwd->servers) httpState->peer = fwd->servers->peer; /* might be NULL */ if (httpState->peer) { diff --git a/src/protos.h b/src/protos.h index 3ca6e01da0..0cb2061cfd 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.302 1999/01/12 23:37:47 wessels Exp $ + * $Id: protos.h,v 1.303 1999/01/15 06:11:45 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -646,7 +646,7 @@ extern void peerDigestStatsReport(const PeerDigest * pd, StoreEntry * e); /* forward.c */ extern void fwdStart(int, StoreEntry *, request_t *, struct in_addr); extern DEFER fwdCheckDeferRead; -extern void fwdFail(FwdState *, int, http_status, int); +extern void fwdFail(FwdState *, ErrorState *); extern void fwdUnregister(int fd, FwdState *); extern void fwdComplete(FwdState * fwdState); extern void fwdInit(void); diff --git a/src/structs.h b/src/structs.h index 309e628bd9..1b12556ede 100644 --- a/src/structs.h +++ b/src/structs.h @@ -2,7 +2,7 @@ /* - * $Id: structs.h,v 1.259 1999/01/12 23:38:40 wessels Exp $ + * $Id: structs.h,v 1.260 1999/01/15 06:11:46 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1593,11 +1593,7 @@ struct _FwdState { request_t *request; FwdServer *servers; int server_fd; - struct { - int err_code; - http_status http_code; - int xerrno; - } fail; + ErrorState *err; time_t start; int n_tries; }; diff --git a/src/wais.cc b/src/wais.cc index f22569943f..5a586c5add 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.126 1999/01/12 23:37:53 wessels Exp $ + * $Id: wais.cc,v 1.127 1999/01/15 06:11:47 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -207,6 +207,7 @@ waisSendRequest(int fd, void *data) comm_write_mbuf(fd, mb, waisSendComplete, waisState); if (EBIT_TEST(waisState->entry->flags, ENTRY_CACHABLE)) storeSetPublicKey(waisState->entry); /* Make it public */ + EBIT_CLR(waisState->entry->flags, ENTRY_FWD_HDR_WAIT); } void diff --git a/src/whois.cc b/src/whois.cc index abb01d8998..5fb184a599 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -1,6 +1,6 @@ /* - * $Id: whois.cc,v 1.8 1999/01/08 21:12:19 wessels Exp $ + * $Id: whois.cc,v 1.9 1999/01/15 06:11:47 wessels Exp $ * * DEBUG: section 75 WHOIS protocol * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -104,7 +104,10 @@ whoisReadReply(int fd, void *data) if (ignoreErrno(errno)) { commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); } else if (entry->mem_obj->inmem_hi == 0) { - fwdFail(p->fwd, ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, errno); + ErrorState *err; + err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); + err->xerrno = errno; + fwdFail(p->fwd, err); comm_close(fd); } else { comm_close(fd); -- 2.47.3