From: wessels <> Date: Tue, 25 Nov 1997 05:32:36 +0000 (+0000) Subject: Fixes to get pipelined client requests working better. Need a function X-Git-Tag: SQUID_3_0_PRE1~4478 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8daca701c8c2ba8c8dd168495210a6c8d12220e9;p=thirdparty%2Fsquid.git Fixes to get pipelined client requests working better. Need a function called storeClientPending() whose purpose is to tell the client side if there is already a callback registered for the entry and the client. If not, then we'll register one via storeClientCopy(). This is due to a race condition; when we have pipelined requests, we can not guarantee that we'll get Deferred in clientSendMoreData() before its time to send the object off to the client, so the original handler may still be in place. --- diff --git a/src/client_side.cc b/src/client_side.cc index 41d788a983..bb13ecbb4d 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.157 1997/11/23 06:50:27 wessels Exp $ + * $Id: client_side.cc,v 1.158 1997/11/24 22:32:36 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -972,13 +972,14 @@ clientWriteComplete(int fd, char *bufnotused, size_t size, int errflag, void *da httpRequestFree(http); if ((http = conn->chr) != NULL) { debug(12, 1) ("clientWriteComplete: FD %d Sending next request\n", fd); - storeClientCopy(entry, - http->out.offset, - http->out.offset, - SM_PAGE_SIZE, - get_free_4k_page(), - clientSendMoreData, - http); + if (!storeClientCopyPending(http->entry, http)) + storeClientCopy(http->entry, + http->out.offset, + http->out.offset, + SM_PAGE_SIZE, + get_free_4k_page(), + clientSendMoreData, + http); } else { debug(12, 5) ("clientWriteComplete: FD %d Setting read handler for next request\n", fd); fd_note(fd, "Reading next request"); @@ -1872,26 +1873,26 @@ clientHttpConnectionsOpen(void) { ushortlist *u; int fd; -debug(0,0)("clientHttpConnectionsOpen\n"); + debug(0, 0) ("clientHttpConnectionsOpen\n"); for (u = Config.Port.http; u; u = u->next) { -debug(0,0)("clientHttpConnectionsOpen: port=%d\n", (int) u->i); - enter_suid(); - fd = comm_open(SOCK_STREAM, - 0, - Config.Addrs.tcp_incoming, - u->i, - COMM_NONBLOCKING, - "HTTP Socket"); - leave_suid(); - if (fd < 0) - continue; - comm_listen(fd); - commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); - commSetDefer(fd, httpAcceptDefer, NULL); - debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n", - (int) u->i, fd); - HttpSockets[NHttpSockets++] = fd; + debug(0, 0) ("clientHttpConnectionsOpen: port=%d\n", (int) u->i); + enter_suid(); + fd = comm_open(SOCK_STREAM, + 0, + Config.Addrs.tcp_incoming, + u->i, + COMM_NONBLOCKING, + "HTTP Socket"); + leave_suid(); + if (fd < 0) + continue; + comm_listen(fd); + commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); + commSetDefer(fd, httpAcceptDefer, NULL); + debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n", + (int) u->i, fd); + HttpSockets[NHttpSockets++] = fd; } if (NHttpSockets < 1) - fatal("Cannot open HTTP Port"); + fatal("Cannot open HTTP Port"); } diff --git a/src/protos.h b/src/protos.h index 0a598a4561..3ec9e63ee0 100644 --- a/src/protos.h +++ b/src/protos.h @@ -443,6 +443,7 @@ extern void storeNegativeCache(StoreEntry *); extern void storeFreeMemory(void); extern int expiresMoreThan(time_t, time_t); extern void storeClientListAdd(StoreEntry *, void *); +extern int storeClientCopyPending(StoreEntry *, void *); extern void InvokeHandlers(StoreEntry *); extern int storeEntryValidToSend(StoreEntry *); extern void storeTimestampsSet(StoreEntry *); diff --git a/src/store.cc b/src/store.cc index 33e95135e6..d7afd0f12d 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.346 1997/11/18 01:02:42 wessels Exp $ + * $Id: store.cc,v 1.347 1997/11/24 22:32:38 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -702,7 +702,6 @@ InvokeHandlers(StoreEntry * e) { int i = 0; MemObject *mem = e->mem_obj; - STCB *callback = NULL; store_client *sc; store_client *nx = NULL; assert(mem->clients != NULL || mem->nclients == 0); @@ -710,10 +709,10 @@ InvokeHandlers(StoreEntry * e) /* walk the entire list looking for valid callbacks */ for (sc = mem->clients; sc; sc = nx) { nx = sc->next; - debug(20, 3) ("InvokeHandlers: checking client #%d\n", i++); + debug(20, 0) ("InvokeHandlers: checking client #%d\n", i++); if (sc->callback_data == NULL) continue; - if ((callback = sc->callback) == NULL) + if (sc->callback == NULL) continue; storeClientCopy2(e, sc); } @@ -1694,7 +1693,7 @@ storeClientCopy(StoreEntry * e, { store_client *sc; static int recurse_detect = 0; - assert(e->store_status != STORE_ABORTED); + /*assert(e->store_status != STORE_ABORTED); */ assert(recurse_detect < 3); /* could == 1 for IMS not modified's */ debug(20, 3) ("storeClientCopy: %s, seen %d, want %d, size %d, cb %p, cbdata %p\n", storeKeyText(e->key), @@ -1798,6 +1797,18 @@ storeClientCopyHandleRead(int fd, const char *buf, int len, int flagnotused, voi callback(sc->callback_data, sc->copy_buf, len); } +int +storeClientCopyPending(StoreEntry * e, void *data) +{ + /* return 1 if there is a callback registered for this client */ + store_client *sc = storeClientListSearch(e->mem_obj, data); + if (sc == NULL) + return 0; + if (sc->callback == NULL) + return 0; + return 1; +} + static int storeEntryValidLength(const StoreEntry * e) { @@ -2378,15 +2389,15 @@ storeCopyNotModifiedReplyHeaders(MemObject * oldmem, MemObject * newmem) /* this just sets DELAY_SENDING */ void -storeBuffer(StoreEntry *e) +storeBuffer(StoreEntry * e) { - EBIT_SET(e->flag, DELAY_SENDING); + EBIT_SET(e->flag, DELAY_SENDING); } /* this just clears DELAY_SENDING and Invokes the handlers */ void -storeBufferFlush(StoreEntry *e) +storeBufferFlush(StoreEntry * e) { - EBIT_CLR(e->flag, DELAY_SENDING); - InvokeHandlers(e); + EBIT_CLR(e->flag, DELAY_SENDING); + InvokeHandlers(e); }