--------------------- PatchSet 10035 Date: 2007/09/25 01:53:31 Author: adri Branch: store_copy Tag: (none) Log: * Convert the rest of client-side over to the new world order * Note that I should be using explicit reference/dereference calls rather than passing by copy structs in C; I'll revisit this in a followup commit to make the reference counting much more explicit. Members: src/client_side.c:1.202.2.1->1.202.2.2 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.1 retrieving revision 1.202.2.2 diff -u -r1.202.2.1 -r1.202.2.2 --- squid/src/client_side.c 25 Sep 2007 00:29:27 -0000 1.202.2.1 +++ squid/src/client_side.c 25 Sep 2007 01:53:31 -0000 1.202.2.2 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.1 2007/09/25 00:29:27 adri Exp $ + * $Id: client_side.c,v 1.202.2.2 2007/09/25 01:53:31 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -123,7 +123,7 @@ static RH clientRedirectDone; static void clientCheckNoCache(clientHttpRequest *); static void clientCheckNoCacheDone(int answer, void *data); -static STCB clientHandleIMSReply; +static STNCB clientHandleIMSReply; static int clientGetsOldEntry(StoreEntry * new, StoreEntry * old, request_t * request); #if USE_IDENT static IDCB clientIdentDone; @@ -135,8 +135,8 @@ #endif /* FOLLOW_X_FORWARDED_FOR */ static int clientOnlyIfCached(clientHttpRequest * http); static STNCB clientSendMoreData; -static STCB clientSendMoreHeaderData; -static STCB clientCacheHit; +static STNCB clientSendMoreHeaderData; +static STNCB clientCacheHit; static void clientSetKeepaliveFlag(clientHttpRequest *); static void clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String boundary, MemBuf * mb); static void clientPackTermBound(String boundary, MemBuf * mb); @@ -399,7 +399,7 @@ if (h->log_type != LOG_TCP_DENIED) delaySetStoreClient(h->sc, delayClient(h)); #endif - storeClientCopy(h->sc, e, 0, 0, STORE_CLIENT_BUF_SZ, memAllocate(MEM_STORE_CLIENT_BUF), clientSendMoreHeaderData, h); + storeClientRef(h->sc, e, 0, 0, STORE_CLIENT_BUF_SZ, clientSendMoreHeaderData, h); return e; } @@ -689,8 +689,9 @@ } static void -clientHandleETagReply(void *data, char *buf, ssize_t size) +clientHandleETagReply(void *data, mem_node_ref ref, ssize_t size) { + //const char *buf = ref.node->data + ref.offset; clientHttpRequest *http = data; StoreEntry *entry = http->entry; MemObject *mem; @@ -699,11 +700,11 @@ debug(33, 3) ("clientHandleETagReply: %s, %d bytes\n", url, (int) size); if (entry == NULL) { /* client aborted */ - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } if (size < 0 && !EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientHandleETagMiss(http); return; } @@ -711,7 +712,7 @@ status = mem->reply->sline.status; if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { debug(33, 3) ("clientHandleETagReply: ABORTED '%s'\n", url); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientHandleETagMiss(http); return; } @@ -720,14 +721,14 @@ if (size >= STORE_CLIENT_BUF_SZ) { /* will not get any bigger than that */ debug(33, 3) ("clientHandleETagReply: Reply is too large '%s'\n", url); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientHandleETagMiss(http); } else { - storeClientCopy(http->sc, entry, + storeClientDeref(&ref); + storeClientRef(http->sc, entry, http->out.offset + size, http->out.offset, STORE_CLIENT_BUF_SZ, - buf, clientHandleETagReply, http); } @@ -735,7 +736,7 @@ } if (HTTP_NOT_MODIFIED == mem->reply->sline.status) { /* Remember the ETag and restart */ - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); if (mem->reply) { request_t *request = http->request; const char *etag = httpHeaderGetStr(&mem->reply->header, HDR_ETAG); @@ -755,7 +756,7 @@ return; } /* Send the new object to the client */ - clientSendMoreHeaderData(data, buf, size); + clientSendMoreHeaderData(data, ref, size); return; } @@ -777,11 +778,10 @@ /* Register with storage manager to receive updates when data comes in. */ if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientProcessETag: found ENTRY_ABORTED object\n"); - storeClientCopy(http->sc, entry, + storeClientRef(http->sc, entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - memAllocate(MEM_STORE_CLIENT_BUF), clientHandleETagReply, http); } @@ -862,11 +862,10 @@ /* 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"); - storeClientCopy(http->sc, entry, + storeClientRef(http->sc, entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - memAllocate(MEM_STORE_CLIENT_BUF), clientHandleIMSReply, http); } @@ -930,7 +929,7 @@ static void -clientHandleIMSReply(void *data, char *buf, ssize_t size) +clientHandleIMSReply(void *data, mem_node_ref ref, ssize_t size) { clientHttpRequest *http = data; StoreEntry *entry = http->entry; @@ -946,11 +945,11 @@ http->old_entry->mem_obj->ims_entry = NULL; } if (entry == NULL) { - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } if (size < 0 && !EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } mem = entry->mem_obj; @@ -977,11 +976,11 @@ http->sc = http->old_sc; /* continue */ } else { - storeClientCopy(http->sc, entry, + storeClientDeref(&ref); + storeClientRef(http->sc, entry, http->out.offset + size, http->out.offset, STORE_CLIENT_BUF_SZ, - buf, clientHandleIMSReply, http); return; @@ -1033,15 +1032,16 @@ http->old_sc = NULL; assert(!EBIT_TEST(entry->flags, ENTRY_ABORTED)); if (recopy) { - storeClientCopy(http->sc, entry, + storeClientDeref(&ref); + storeClientRef(http->sc, entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - buf, clientSendMoreHeaderData, http); } else { - clientSendMoreHeaderData(data, buf, size); + /* XXX should be passing in a reference call, and dereferencing our copy! [ahc] */ + clientSendMoreHeaderData(data, ref, size); } } @@ -1116,11 +1116,10 @@ http->entry->mem_obj->method = http->request->method; http->sc = storeClientRegister(http->entry, http); http->log_type = LOG_TCP_HIT; - storeClientCopy(http->sc, http->entry, + storeClientRef(http->sc, http->entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - memAllocate(MEM_STORE_CLIENT_BUF), clientCacheHit, http); return; @@ -2116,7 +2115,7 @@ * clientProcessMiss. */ static void -clientCacheHit(void *data, char *buf, ssize_t size) +clientCacheHit(void *data, mem_node_ref ref, ssize_t size) { clientHttpRequest *http = data; StoreEntry *e = http->entry; @@ -2127,12 +2126,12 @@ debug(33, 3) ("clientCacheHit: %s, %d bytes\n", http->uri, (int) size); http->flags.hit = 0; if (http->entry == NULL) { - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); debug(33, 3) ("clientCacheHit: request aborted\n"); return; } else if (size <= 0) { /* swap in failure */ - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); debug(33, 3) ("clientCacheHit: swapin failure for %s\n", http->uri); http->log_type = LOG_TCP_SWAPFAIL_MISS; clientProcessMiss(http); @@ -2143,13 +2142,13 @@ assert(!EBIT_TEST(e->flags, ENTRY_ABORTED)); if (!memHaveHeaders(mem)) { debug(33, 1) ("clientCacheHit: No reply headers in '%s'?\n", e->mem_obj->url); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientProcessMiss(http); return; } if (strcmp(mem->url, urlCanonical(r)) != 0) { debug(33, 1) ("clientCacheHit: URL mismatch '%s' != '%s'?\n", e->mem_obj->url, urlCanonical(r)); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientProcessMiss(http); return; } @@ -2185,7 +2184,7 @@ * so we only get here once. (it also takes care of cancelling loops) */ debug(33, 2) ("clientProcessHit: Vary detected!\n"); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } case VARY_RESTART: @@ -2195,13 +2194,13 @@ safe_free(r->vary_hdr); safe_free(r->vary_headers); clientProcessRequest(http); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; case VARY_CANCEL: /* varyEvaluateMatch found a object loop. Process as miss */ debug(33, 1) ("clientProcessHit: Vary object loop!\n"); clientProcessMiss(http); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } if (r->method == METHOD_PURGE) { @@ -2210,7 +2209,7 @@ http->sc = NULL; storeUnlockObject(e); clientPurgeRequest(http); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } http->flags.hit = 1; @@ -2221,10 +2220,11 @@ #endif ) { http->log_type = LOG_TCP_NEGATIVE_HIT; - clientSendMoreHeaderData(data, buf, size); + /* XXX should be passing in a reference call, and dereferncing our copy! [ahc] */ + clientSendMoreHeaderData(data, ref, size); } else { http->log_type = LOG_TCP_MISS; - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientProcessMiss(http); } return; @@ -2242,7 +2242,7 @@ * Query the origin to see what should be done. */ http->log_type = LOG_TCP_MISS; - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientProcessMiss(http); return; } @@ -2255,7 +2255,7 @@ debug(33, 4) ("clientCacheHit: Reply code %d != 200\n", mem->reply->sline.status); http->log_type = LOG_TCP_MISS; - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientProcessMiss(http); return; } @@ -2321,7 +2321,7 @@ } else { clientProcessExpired(http); } - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } if (is_modified == 0) { @@ -2343,7 +2343,7 @@ storeAppend(e, mb.buf, mb.size); memBufClean(&mb); storeComplete(e); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } /* @@ -2353,7 +2353,8 @@ http->log_type = LOG_TCP_MISS; else if (http->log_type == LOG_TCP_HIT && e->mem_status == IN_MEMORY) http->log_type = LOG_TCP_MEM_HIT; - clientSendMoreHeaderData(data, buf, size); + /* XXX should be passing it in with a reference call, and dereferencing our copy! [ahc] */ + clientSendMoreHeaderData(data, ref, size); } /* put terminating boundary for multiparts */ @@ -2611,8 +2612,9 @@ * such, writes processed message to the client's socket */ static void -clientSendMoreHeaderData(void *data, char *buf, ssize_t size) +clientSendMoreHeaderData(void *data, mem_node_ref ref, ssize_t size) { + //const char *buf = ref.node->data + ref.offset; clientHttpRequest *http = data; StoreEntry *entry = http->entry; ConnStateData *conn = http->conn; @@ -2629,26 +2631,26 @@ if (DLINK_HEAD(conn->reqs) != http) { /* there is another object in progress, defer this one */ debug(33, 2) ("clientSendMoreHeaderData: Deferring %s\n", storeUrl(entry)); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } else if (http->request->flags.reset_tcp) { comm_reset_close(fd); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } else if (entry && EBIT_TEST(entry->flags, ENTRY_ABORTED)) { /* call clientWriteComplete so the client socket gets closed */ - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientWriteComplete(fd, NULL, 0, COMM_OK, http); return; } else if (size < 0) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } else if (size == 0) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } assert(http->out.offset == 0); @@ -2661,7 +2663,7 @@ http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags); errorAppendEntry(http->entry, err); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } clientMaxBodySize(http->request, http, rep); @@ -2674,7 +2676,7 @@ http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags); errorAppendEntry(http->entry, err); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); return; } /* @@ -2689,7 +2691,7 @@ */ http->range_iter.prefix_size = rep->hdr_sz; debug(33, 3) ("clientSendMoreHeaderData: %d bytes of headers\n", rep->hdr_sz); - memFree(buf, MEM_STORE_CLIENT_BUF); + storeClientDeref(&ref); clientHttpLocationRewriteCheck(http); } @@ -3045,11 +3047,10 @@ if (0 == storeClientCopyPending(http->sc, entry, http)) { if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) debug(33, 0) ("clientKeepaliveNextRequest: ENTRY_ABORTED\n"); - storeClientCopy(http->sc, entry, + storeClientRef(http->sc, entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - memAllocate(MEM_STORE_CLIENT_BUF), clientSendMoreHeaderData, http); } @@ -3356,11 +3357,10 @@ #if DELAY_POOLS delaySetStoreClient(http->sc, delayClient(http)); #endif - storeClientCopy(http->sc, http->entry, + storeClientRef(http->sc, http->entry, http->out.offset, http->out.offset, STORE_CLIENT_BUF_SZ, - memAllocate(MEM_STORE_CLIENT_BUF), clientCacheHit, http); } else {