--------------------- PatchSet 10178 Date: 2007/11/30 04:29:03 Author: adri Branch: store_copy Tag: (none) Log: Convert the net_db code over to use storeClientRef() Members: src/net_db.c:1.26->1.26.2.1 Index: squid/src/net_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/net_db.c,v retrieving revision 1.26 retrieving revision 1.26.2.1 diff -u -r1.26 -r1.26.2.1 --- squid/src/net_db.c 23 Sep 2007 14:51:44 -0000 1.26 +++ squid/src/net_db.c 30 Nov 2007 04:29:03 -0000 1.26.2.1 @@ -1,6 +1,6 @@ /* - * $Id: net_db.c,v 1.26 2007/09/23 14:51:44 squidadm Exp $ + * $Id: net_db.c,v 1.26.2.1 2007/11/30 04:29:03 adri Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -44,8 +44,6 @@ request_t *r; squid_off_t seen; squid_off_t used; - size_t buf_sz; - char *buf; } netdbExchangeState; static hash_table *addr_table = NULL; @@ -68,7 +66,7 @@ static QS netdbLRU; static FREE netdbFreeNameEntry; static FREE netdbFreeNetdbEntry; -static STCB netdbExchangeHandleReply; +static STNCB netdbExchangeHandleReply; static void netdbExchangeDone(void *); #if USE_ICMP void netdbDump(StoreEntry * sentry); @@ -530,19 +528,22 @@ } static void -netdbExchangeHandleReply(void *data, char *buf, ssize_t size) +netdbExchangeHandleReply(void *data, mem_node_ref nr, ssize_t size) { + const char *buf = nr.node->data + nr.offset; netdbExchangeState *ex = data; int rec_sz = 0; ssize_t o; struct in_addr addr; double rtt; double hops; - char *p; + const char *p; int j; HttpReply *rep; size_t hdr_sz; int nused = 0; + assert(size <= nr.node->len - nr.offset); + rec_sz = 0; rec_sz += 1 + sizeof(addr.s_addr); rec_sz += 1 + sizeof(int); @@ -552,7 +553,7 @@ if (!cbdataValid(ex->p)) { debug(38, 3) ("netdbExchangeHandleReply: Peer became invalid\n"); netdbExchangeDone(ex); - return; + goto finish; } debug(38, 3) ("netdbExchangeHandleReply: for '%s:%d'\n", ex->p->host, ex->p->http_port); p = buf; @@ -567,17 +568,17 @@ rep->sline.status); if (HTTP_OK != rep->sline.status) { netdbExchangeDone(ex); - return; + goto finish; } assert(size >= hdr_sz); ex->used += hdr_sz; size -= hdr_sz; p += hdr_sz; } else { - if (size >= ex->buf_sz) { + if (size >= SM_PAGE_SIZE) { debug(38, 3) ("netdbExchangeHandleReply: Too big HTTP header, aborting\n"); netdbExchangeDone(ex); - return; + goto finish; } else { size = 0; } @@ -612,7 +613,7 @@ default: debug(38, 1) ("netdbExchangeHandleReply: corrupt data, aborting\n"); netdbExchangeDone(ex); - return; + goto finish; } } if (addr.s_addr != any_addr.s_addr && rtt > 0) @@ -636,16 +637,19 @@ netdbExchangeDone(ex); } else if (ex->e->store_status == STORE_PENDING) { debug(38, 3) ("netdbExchangeHandleReply: STORE_PENDING\n"); - storeClientCopy(ex->sc, ex->e, ex->seen, ex->used, ex->buf_sz, - ex->buf, netdbExchangeHandleReply, ex); + storeClientRef(ex->sc, ex->e, ex->seen, ex->used, SM_PAGE_SIZE, + netdbExchangeHandleReply, ex); } else if (ex->seen < ex->e->mem_obj->inmem_hi) { debug(38, 3) ("netdbExchangeHandleReply: ex->e->mem_obj->inmem_hi\n"); - storeClientCopy(ex->sc, ex->e, ex->seen, ex->used, ex->buf_sz, - ex->buf, netdbExchangeHandleReply, ex); + storeClientRef(ex->sc, ex->e, ex->seen, ex->used, SM_PAGE_SIZE, + netdbExchangeHandleReply, ex); } else { debug(38, 3) ("netdbExchangeHandleReply: Done\n"); netdbExchangeDone(ex); } +finish: + buf = NULL; + stmemNodeUnref(&nr); } static void @@ -653,7 +657,6 @@ { netdbExchangeState *ex = data; debug(38, 3) ("netdbExchangeDone: %s\n", storeUrl(ex->e)); - memFree(ex->buf, MEM_4K_BUF); requestUnlink(ex->r); storeClientUnregister(ex->sc, ex->e, ex); storeUnlockObject(ex->e); @@ -997,12 +1000,10 @@ assert(NULL != ex->r); httpBuildVersion(&ex->r->http_ver, 1, 0); ex->e = storeCreateEntry(uri, null_request_flags, METHOD_GET); - ex->buf_sz = 4096; - ex->buf = memAllocate(MEM_4K_BUF); assert(NULL != ex->e); ex->sc = storeClientRegister(ex->e, ex); - storeClientCopy(ex->sc, ex->e, ex->seen, ex->used, ex->buf_sz, - ex->buf, netdbExchangeHandleReply, ex); + storeClientRef(ex->sc, ex->e, ex->seen, ex->used, SM_PAGE_SIZE, + netdbExchangeHandleReply, ex); ex->r->flags.loopdetect = 1; /* cheat! -- force direct */ if (p->login) xstrncpy(ex->r->login, p->login, MAX_LOGIN_SZ);