--------------------- PatchSet 10180 Date: 2007/11/30 07:44:23 Author: adri Branch: store_copy Tag: (none) Log: Second half of the storeClientRef() changes to the peer digest code. This hasn't been completely tested! Members: src/peer_digest.c:1.21.10.1->1.21.10.2 Index: squid/src/peer_digest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_digest.c,v retrieving revision 1.21.10.1 retrieving revision 1.21.10.2 diff -u -r1.21.10.1 -r1.21.10.2 --- squid/src/peer_digest.c 30 Nov 2007 07:21:11 -0000 1.21.10.1 +++ squid/src/peer_digest.c 30 Nov 2007 07:44:23 -0000 1.21.10.2 @@ -1,6 +1,6 @@ /* - * $Id: peer_digest.c,v 1.21.10.1 2007/11/30 07:21:11 adri Exp $ + * $Id: peer_digest.c,v 1.21.10.2 2007/11/30 07:44:23 adri Exp $ * * DEBUG: section 72 Peer Digest Routines * AUTHOR: Alex Rousskov @@ -49,7 +49,7 @@ static STNCB peerDigestFetchReply; static STNCB peerDigestSwapInHeaders; static STNCB peerDigestSwapInCBlock; -static STCB peerDigestSwapInMask; +static STNCB peerDigestSwapInMask; static int peerDigestFetchedEnough(DigestFetchState * fetch, const char *buf, ssize_t size, const char *step_name); static void peerDigestFetchStop(DigestFetchState * fetch, const char *buf, const char *reason); static void peerDigestFetchAbort(DigestFetchState * fetch, const char *buf, const char *reason); @@ -469,11 +469,10 @@ fetch->offset += StoreDigestCBlockSize; /* switch to CD buffer and fetch digest guts */ assert(pd->cd->mask); - storeClientCopy(fetch->sc, fetch->entry, + storeClientRef(fetch->sc, fetch->entry, seen, fetch->offset, pd->cd->mask_size, - pd->cd->mask, peerDigestSwapInMask, fetch); } else { peerDigestFetchAbort(fetch, buf, "invalid digest cblock"); @@ -491,18 +490,29 @@ } static void -peerDigestSwapInMask(void *data, char *buf, ssize_t size) +peerDigestSwapInMask(void *data, mem_node_ref nr, ssize_t size) { + const char *buf = nr.node->data + nr.offset; DigestFetchState *fetch = data; PeerDigest *pd; + assert(size <= nr.node->len - nr.offset); + + /* XXX this used to be before peerDigestFetchedEnough() was called.. */ + pd = fetch->pd; + assert(pd->cd && pd->cd->mask); + /* Emulate old behaviour - the data is already copied before this function is called */ /* NOTE! buf points to the middle of pd->cd->mask! */ + if (size > 0) { + /* XXX need to assert that size fits inside the buffer size! */ + assert(size + fetch->mask_offset < pd->cd->mask_size); + memcpy(pd->cd->mask + fetch->mask_offset, buf, size); + } + stmemNodeUnref(&nr); + if (peerDigestFetchedEnough(fetch, NULL, size, "peerDigestSwapInMask")) return; - pd = fetch->pd; - assert(pd->cd && pd->cd->mask); - fetch->offset += size; fetch->mask_offset += size; if (fetch->mask_offset >= pd->cd->mask_size) { @@ -513,11 +523,10 @@ } else { const size_t buf_sz = pd->cd->mask_size - fetch->mask_offset; assert(buf_sz > 0); - storeClientCopy(fetch->sc, fetch->entry, + storeClientRef(fetch->sc, fetch->entry, fetch->offset, fetch->offset, buf_sz, - pd->cd->mask + fetch->mask_offset, peerDigestSwapInMask, fetch); } }