--------------------- PatchSet 1066 Date: 2001/01/04 14:23:12 Author: adri Branch: modio Tag: (none) Log: Initial commit of my quest to kill seen_offset: * make the MEM_CLIENT_SOCK_BUF a single buffer which is persistent for the lifetime of a http client connection. This is used instead of constantly allocating/free'ing memory. (This may introduce more "problems" later on which will probably resemble random memory trashings and corrupt objects, but those are going to be definite problems which need fixing regardless.. :-) * kill the use of seen_offset in client_side.c . Its still used in other places, but squid will assert() if the code is run (I'll eventually get around to fixing them all, but the client_side code is much more important to me right now..) Here, we are simply tracking the offset (h->bufofs) and copying data between it and the end of the buffer. Its not pretty, but it'll do for the time being. Members: src/client_side.c:1.2.2.8->1.2.2.9 src/structs.h:1.2.2.11->1.2.2.12 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.2.2.8 retrieving revision 1.2.2.9 diff -u -r1.2.2.8 -r1.2.2.9 --- squid/src/client_side.c 20 Dec 2000 15:45:55 -0000 1.2.2.8 +++ squid/src/client_side.c 4 Jan 2001 14:23:12 -0000 1.2.2.9 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.2.2.8 2000/12/20 15:45:55 adri Exp $ + * $Id: client_side.c,v 1.2.2.9 2001/01/04 14:23:12 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -116,6 +116,17 @@ static log_type clientProcessRequest2(clientHttpRequest * http); static int clientReplyBodyTooLarge(int clen); static int clientRequestBodyTooLarge(int clen); +static void httpMemFree(void *, int); + + +static void httpMemFree(void *data, int notused) +{ + clientHttpRequest *h = data; + + memFree(h->buf, MEM_CLIENT_SOCK_BUF); + memFree(h, MEM_CLIENTHTTPREQUEST); +} + static int checkAccelOnly(clientHttpRequest * http) @@ -208,8 +219,8 @@ #if DELAY_POOLS delaySetStoreClient(h->sc, delayClient(h->request)); #endif - storeClientCopy(e, 0, 0, CLIENT_SOCK_SZ, - memAllocate(MEM_CLIENT_SOCK_BUF), clientSendMoreData, h); + h->bufofs = 0; + storeClientCopy(e, 0, 0, CLIENT_SOCK_SZ, h->buf, clientSendMoreData, h); return e; } @@ -391,11 +402,12 @@ /* Register with storage manager to receive updates when data comes in. */ if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientProcessExpired: found ENTRY_ABORTED object\n"); + http->bufofs = 0; storeClientCopy(entry, http->out.offset, http->out.offset, CLIENT_SOCK_SZ, - memAllocate(MEM_CLIENT_SOCK_BUF), + http->buf, clientHandleIMSReply, http); } @@ -451,11 +463,9 @@ http_status status; debug(33, 3) ("clientHandleIMSReply: %s, %d bytes\n", url, (int) size); if (entry == NULL) { - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } if (size < 0 && !EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } mem = entry->mem_obj; @@ -480,11 +490,13 @@ entry = http->entry = http->old_entry; /* continue */ } else { + http->bufofs += size; + assert(http->bufofs <= CLIENT_SOCK_SZ); storeClientCopy(entry, - http->out.offset + size, - http->out.offset, - CLIENT_SOCK_SZ, - buf, + http->out.offset + http->bufofs, + http->out.offset + http->bufofs, + CLIENT_SOCK_SZ - http->bufofs, + buf + http->bufofs, clientHandleIMSReply, http); return; @@ -529,6 +541,7 @@ http->old_entry = NULL; /* done with old_entry */ assert(!EBIT_TEST(entry->flags, ENTRY_ABORTED)); if (recopy) { + http->bufofs = 0; storeClientCopy(entry, http->out.offset, http->out.offset, @@ -1340,12 +1353,10 @@ request_t *r = http->request; debug(33, 3) ("clientCacheHit: %s, %d bytes\n", http->uri, (int) size); if (http->entry == NULL) { - memFree(buf, MEM_CLIENT_SOCK_BUF); debug(33, 3) ("clientCacheHit: request aborted\n"); return; } else if (size < 0) { /* swap in failure */ - memFree(buf, MEM_CLIENT_SOCK_BUF); debug(33, 3) ("clientCacheHit: swapin failure for %s\n", http->uri); http->log_type = LOG_TCP_SWAPFAIL_MISS; if ((e = http->entry)) { @@ -1365,18 +1376,18 @@ * punt to clientProcessMiss. */ if (e->mem_status == IN_MEMORY || e->store_status == STORE_OK) { - memFree(buf, MEM_CLIENT_SOCK_BUF); clientProcessMiss(http); } else if (size == CLIENT_SOCK_SZ && http->out.offset == 0) { - memFree(buf, MEM_CLIENT_SOCK_BUF); clientProcessMiss(http); } else { debug(33, 3) ("clientCacheHit: waiting for HTTP reply headers\n"); + http->bufofs += size; + assert(http->bufofs <= CLIENT_SOCK_SZ); storeClientCopy(e, - http->out.offset + size, - http->out.offset, - CLIENT_SOCK_SZ, - buf, + http->out.offset + http->bufofs, + http->out.offset + http->bufofs, + CLIENT_SOCK_SZ - http->bufofs, + buf + http->bufofs, clientCacheHit, http); } @@ -1440,7 +1451,6 @@ http->log_type = LOG_TCP_MISS; clientProcessMiss(http); } - memFree(buf, MEM_CLIENT_SOCK_BUF); } else if (r->flags.ims) { /* * Handle If-Modified-Since requests from the client @@ -1448,7 +1458,6 @@ if (mem->reply->sline.status != HTTP_OK) { debug(33, 4) ("clientCacheHit: Reply code %d != 200\n", mem->reply->sline.status); - memFree(buf, MEM_CLIENT_SOCK_BUF); http->log_type = LOG_TCP_MISS; clientProcessMiss(http); } else if (modifiedSince(e, http->request)) { @@ -1458,7 +1467,6 @@ time_t timestamp = e->timestamp; MemBuf mb = httpPacked304Reply(e->mem_obj->reply); http->log_type = LOG_TCP_IMS_HIT; - memFree(buf, MEM_CLIENT_SOCK_BUF); storeClientUnregister(e, http); storeUnlockObject(e); e = clientCreateStoreEntry(http, http->request->method, null_request_flags); @@ -1698,22 +1706,18 @@ if (conn->chr != http) { /* there is another object in progress, defer this one */ debug(33, 1) ("clientSendMoreData: Deferring %s\n", storeUrl(entry)); - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } else if (entry && EBIT_TEST(entry->flags, ENTRY_ABORTED)) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } else if (size < 0) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } else if (size == 0) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); - memFree(buf, MEM_CLIENT_SOCK_BUF); return; } if (http->out.offset == 0) { @@ -1745,11 +1749,13 @@ body_size, rep->hdr_sz); } else if (size < CLIENT_SOCK_SZ && entry->store_status == STORE_PENDING) { /* wait for more to arrive */ + http->bufofs += size; + assert(http->bufofs <= CLIENT_SOCK_SZ); storeClientCopy(entry, - http->out.offset + size, - http->out.offset, - CLIENT_SOCK_SZ, - buf, + http->out.offset + http->bufofs, + http->out.offset + http->bufofs, + CLIENT_SOCK_SZ - http->bufofs, + buf + http->bufofs, clientSendMoreData, http); return; @@ -1814,7 +1820,6 @@ /* write */ comm_write_mbuf(fd, mb, clientWriteComplete, http); /* if we don't do it, who will? */ - memFree(buf, MEM_CLIENT_SOCK_BUF); } /* @@ -1831,7 +1836,6 @@ * (second) argument, so we pass in NULL. */ clientWriteComplete(fd, NULL, size, errflag, data); - memFree(buf, MEM_CLIENT_SOCK_BUF); } static void @@ -1876,11 +1880,12 @@ if (0 == storeClientCopyPending(entry, http)) { if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientKeepaliveNextRequest: ENTRY_ABORTED\n"); + http->bufofs = 0; storeClientCopy(entry, http->out.offset, http->out.offset, CLIENT_SOCK_SZ, - memAllocate(MEM_CLIENT_SOCK_BUF), + http->buf, clientSendMoreData, http); } @@ -1935,11 +1940,12 @@ * storage manager. */ if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientWriteComplete 2: ENTRY_ABORTED\n"); + http->bufofs = 0; storeClientCopy(entry, http->out.offset, http->out.offset, CLIENT_SOCK_SZ, - memAllocate(MEM_CLIENT_SOCK_BUF), + http->buf, clientSendMoreData, http); } @@ -2148,11 +2154,12 @@ #if DELAY_POOLS delaySetStoreClient(http->sc, delayClient(r)); #endif + http->bufofs = 0; storeClientCopy(http->entry, http->out.offset, http->out.offset, CLIENT_SOCK_SZ, - memAllocate(MEM_CLIENT_SOCK_BUF), + http->buf, clientCacheHit, http); } else { @@ -2225,13 +2232,14 @@ parseHttpRequestAbort(ConnStateData * conn, const char *uri) { clientHttpRequest *http = memAllocate(MEM_CLIENTHTTPREQUEST); - cbdataAdd(http, memFree, MEM_CLIENTHTTPREQUEST); + cbdataAdd(http, httpMemFree, MEM_CLIENTHTTPREQUEST); http->conn = conn; http->start = current_time; http->req_sz = conn->in.offset; http->uri = xstrdup(uri); http->log_uri = xstrndup(uri, MAX_URL); http->range_iter.boundary = StringNull; + http->buf = memAllocate(MEM_CLIENT_SOCK_BUF); dlinkAdd(http, &http->active, &ClientActiveRequests); return http; } @@ -2365,12 +2373,13 @@ /* Ok, all headers are received */ http = memAllocate(MEM_CLIENTHTTPREQUEST); - cbdataAdd(http, memFree, MEM_CLIENTHTTPREQUEST); + cbdataAdd(http, httpMemFree, MEM_CLIENTHTTPREQUEST); http->http_ver = http_ver; http->conn = conn; http->start = current_time; http->req_sz = prefix_sz; http->range_iter.boundary = StringNull; + http->buf = memAllocate(MEM_CLIENT_SOCK_BUF); *prefix_p = xmalloc(prefix_sz + 1); xmemcpy(*prefix_p, conn->in.buf, prefix_sz); *(*prefix_p + prefix_sz) = '\0'; Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.2.2.11 retrieving revision 1.2.2.12 diff -u -r1.2.2.11 -r1.2.2.12 --- squid/src/structs.h 2 Jan 2001 14:05:32 -0000 1.2.2.11 +++ squid/src/structs.h 4 Jan 2001 14:23:12 -0000 1.2.2.12 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.2.2.11 2001/01/02 14:05:32 adri Exp $ + * $Id: structs.h,v 1.2.2.12 2001/01/04 14:23:12 adri Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -905,6 +905,8 @@ char *location; } redirect; dlink_node active; + char *buf; /* transient buffer... eeeew! */ + int bufofs; /* offset in the current buffer .. */ }; struct _ConnStateData {