--------------------- PatchSet 2231 Date: 2001/05/07 13:23:40 Author: rbcollins Branch: newhttp Tag: (none) Log: refcounted iobuffers Members: src/Makefile.in:1.1.1.3.8.8.2.10.2.1->1.1.1.3.8.8.2.10.2.2 src/cbdata.c:1.1.1.2.12.4.4.2.2.1->1.1.1.2.12.4.4.2.2.2 src/comm.c:1.1.1.3.8.7.4.3.2.4->1.1.1.3.8.7.4.3.2.5 src/defines.h:1.1.1.3.8.7.2.8.2.2->1.1.1.3.8.7.2.8.2.3 src/http.c:1.1.1.3.4.1.4.12.2.16.2.7->1.1.1.3.4.1.4.12.2.16.2.8 src/protos.h:1.1.1.3.8.11.2.20.2.4->1.1.1.3.8.11.2.20.2.5 Index: squid/src/Makefile.in =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/Makefile.in,v retrieving revision 1.1.1.3.8.8.2.10.2.1 retrieving revision 1.1.1.3.8.8.2.10.2.2 diff -u -r1.1.1.3.8.8.2.10.2.1 -r1.1.1.3.8.8.2.10.2.2 --- squid/src/Makefile.in 1 May 2001 00:59:02 -0000 1.1.1.3.8.8.2.10.2.1 +++ squid/src/Makefile.in 7 May 2001 13:23:40 -0000 1.1.1.3.8.8.2.10.2.2 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.1.1.3.8.8.2.10.2.1 2001/05/01 00:59:02 rbcollins Exp $ +# $Id: Makefile.in,v 1.1.1.3.8.8.2.10.2.2 2001/05/07 13:23:40 rbcollins Exp $ # # Uncomment and customize the following to suit your needs: # @@ -142,6 +142,7 @@ ident.o \ internal.o \ internal_modules.o \ + iobuf.o \ ipc.o \ ipcache.o \ @LEAKFINDER_OBJS@ \ Index: squid/src/cbdata.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cbdata.c,v retrieving revision 1.1.1.2.12.4.4.2.2.1 retrieving revision 1.1.1.2.12.4.4.2.2.2 diff -u -r1.1.1.2.12.4.4.2.2.1 -r1.1.1.2.12.4.4.2.2.2 --- squid/src/cbdata.c 3 May 2001 14:09:29 -0000 1.1.1.2.12.4.4.2.2.1 +++ squid/src/cbdata.c 7 May 2001 13:23:41 -0000 1.1.1.2.12.4.4.2.2.2 @@ -1,6 +1,6 @@ /* - * $Id: cbdata.c,v 1.1.1.2.12.4.4.2.2.1 2001/05/03 14:09:29 rbcollins Exp $ + * $Id: cbdata.c,v 1.1.1.2.12.4.4.2.2.2 2001/05/07 13:23:41 rbcollins Exp $ * * DEBUG: section 45 Callback Data Registry * ORIGINAL AUTHOR: Duane Wessels @@ -89,13 +89,16 @@ struct { MemPool *pool; FREE *free_func; + struct { + unsigned int freeonunlock:1; + } flags; } *cbdata_index = NULL; int cbdata_types = 0; #define OFFSET_OF(type, member) ((int)(char *)&((type *)0L)->member) void -cbdataInitType(cbdata_type type, char *name, int size, FREE * free_func) +cbdataInitType(cbdata_type type, char *name, int size, FREE * free_func, int freeonunlock) { char *label; if (type >= cbdata_types) { @@ -111,15 +114,18 @@ assert(OFFSET_OF(cbdata, data) == (sizeof(cbdata) - sizeof(((cbdata *) NULL)->data))); cbdata_index[type].pool = memPoolCreate(label, size + OFFSET_OF(cbdata, data)); cbdata_index[type].free_func = free_func; + assert(0 <= freeonunlock <= 1); + /* this is reversed here for perf later */ + cbdata_index[type].flags.freeonunlock=freeonunlock ? 0 : 1; } cbdata_type -cbdataAddType(cbdata_type type, char *name, int size, FREE * free_func) +cbdataAddType(cbdata_type type, char *name, int size, FREE * free_func, int freeonunlock) { if (type) return type; type = cbdata_types; - cbdataInitType(type, name, size, free_func); + cbdataInitType(type, name, size, free_func, freeonunlock); return type; } @@ -130,8 +136,8 @@ cachemgrRegister("cbdata", "Callback Data Registry Contents", cbdataDump, 0, 1); -#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL) -#define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func) +#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL, 0) +#define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func, 0) CREATE_CBDATA(acl_access); CREATE_CBDATA(aclCheck_t); CREATE_CBDATA(clientHttpRequest); @@ -251,7 +257,8 @@ c->file = file; c->line = line; #endif - if (c->valid || c->locks) + /* the freeonunlock flag _is reversed_ */ + if ((cbdata_index[c->type].flags.freeonunlock && c->valid) || c->locks) return; cbdataCount--; debug(45, 3) ("cbdataUnlock: Freeing %p\n", p); Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.1.1.3.8.7.4.3.2.4 retrieving revision 1.1.1.3.8.7.4.3.2.5 diff -u -r1.1.1.3.8.7.4.3.2.4 -r1.1.1.3.8.7.4.3.2.5 --- squid/src/comm.c 7 May 2001 12:01:44 -0000 1.1.1.3.8.7.4.3.2.4 +++ squid/src/comm.c 7 May 2001 13:23:41 -0000 1.1.1.3.8.7.4.3.2.5 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.1.1.3.8.7.4.3.2.4 2001/05/07 12:01:44 adri Exp $ + * $Id: comm.c,v 1.1.1.3.8.7.4.3.2.5 2001/05/07 13:23:41 rbcollins Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1023,7 +1023,7 @@ CommReadStateData *rstate = &F->rstate; /* Check to see if the buffer is valid */ - if (!cbdataValid(rstate->buf) || !cbdataValid(rstate->handler_data)) + if (!cbdataValid(rstate->buf) || !cbdataValid(rstate->handler_data)) return; /* Attempt a read */ Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.1.1.3.8.7.2.8.2.2 retrieving revision 1.1.1.3.8.7.2.8.2.3 diff -u -r1.1.1.3.8.7.2.8.2.2 -r1.1.1.3.8.7.2.8.2.3 --- squid/src/defines.h 1 May 2001 00:59:29 -0000 1.1.1.3.8.7.2.8.2.2 +++ squid/src/defines.h 7 May 2001 13:23:41 -0000 1.1.1.3.8.7.2.8.2.3 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.1.1.3.8.7.2.8.2.2 2001/05/01 00:59:29 rbcollins Exp $ + * $Id: defines.h,v 1.1.1.3.8.7.2.8.2.3 2001/05/07 13:23:41 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -283,8 +283,9 @@ #define cbdataFree(var) (var = (var != NULL ? cbdataInternalFree(var): NULL)) #define CBDATA_TYPE(type) static cbdata_type CBDATA_##type = 0 #define CBDATA_GLOBAL_TYPE(type) cbdata_type CBDATA_##type -#define CBDATA_INIT_TYPE(type) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), NULL))) -#define CBDATA_INIT_TYPE_FREECB(type, free_func) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), free_func))) +#define CBDATA_INIT_TYPE(type) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), NULL, 0))) +#define CBDATA_INIT_TYPE_FREECB(type, free_func) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), free_func, 0))) +#define CBDATA_INIT_TYPE_FREECB_ONUNLOCK(type, free_func) (CBDATA_##type ? 0 : (CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type), free_func, 1))) #ifndef O_TEXT #define O_TEXT 0 Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.1.1.3.4.1.4.12.2.16.2.7 retrieving revision 1.1.1.3.4.1.4.12.2.16.2.8 diff -u -r1.1.1.3.4.1.4.12.2.16.2.7 -r1.1.1.3.4.1.4.12.2.16.2.8 --- squid/src/http.c 7 May 2001 11:46:03 -0000 1.1.1.3.4.1.4.12.2.16.2.7 +++ squid/src/http.c 7 May 2001 13:23:41 -0000 1.1.1.3.4.1.4.12.2.16.2.8 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.1.1.3.4.1.4.12.2.16.2.7 2001/05/07 11:46:03 rbcollins Exp $ + * $Id: http.c,v 1.1.1.3.4.1.4.12.2.16.2.8 2001/05/07 13:23:41 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -39,6 +39,7 @@ */ #include "squid.h" +#include "iobuf.h" static const char *const crlf = "\r\n"; @@ -57,9 +58,6 @@ /* this will go in a header when this file becomes a module */ -typedef struct _iobuf iobuf; -typedef struct _buf4k buf4k; - struct _HttpStateData { StoreEntry *entry; request_t *request; @@ -92,22 +90,7 @@ iobuf *readbuf; }; -struct _iobuf { - /* used when passing an already alloced buffer to an io routine */ - off_t offset; - /* sizeof(*buffer) */ - size_t size; - /* well duh! */ - void * buffer; -}; - -struct _buf4k { - char data[4096]; -}; - CBDATA_TYPE(HttpStateData); -CBDATA_TYPE(iobuf); -CBDATA_TYPE(buf4k); /* temporary function */ void @@ -1402,7 +1385,7 @@ rvflags=temp_filter->filter(howmuch ? readbuf->buffer : NULL, howmuch,http->read_offset-howmuch, &http->hcrequest->repfilters, temp_filter,eofflag,temp_filter->data); - cbdataUnlock(readbuf); + ioBufferUnlock(readbuf); /* TODO: one of the filters needs to be a pipeline request handler that gets the next request handled correctly - setups this func up again */ debug (33,3)("Process request got flags %0x from rep_filter\n", rvflags); /* TODO: cancel the read in some fashion if EOF is signalled after a read is queued */ @@ -1448,7 +1431,7 @@ debug (33,3)("Process request got flags %0x from rep_filter\n", rvflags); } /* all data written */ - cbdataUnlock(readbuf); /* FIXME: make iobuf unlock the buffer */ + ioBufferUnlock(readbuf); } @@ -1501,17 +1484,9 @@ if (http->readbuf) /* theres a write to the client in progress, or an attempt to queue multiple reads*/ return; - CBDATA_INIT_TYPE(iobuf); - CBDATA_INIT_TYPE(buf4k); - readbuf = cbdataAlloc(iobuf); + readbuf = ioBufferAlloc(4096); assert(readbuf); - memset(readbuf,'\0', sizeof(iobuf)); - readbuf->size = sizeof(buf4k); - readbuf->buffer = cbdataAlloc(buf4k); - assert(readbuf->buffer); - cbdataLock(readbuf->buffer); http->readbuf=readbuf; - cbdataLock(http->readbuf); comm_read(http->fd, readbuf->buffer, readbuf->offset, readbuf->size, httpCommReadComplete, http); } Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.8.11.2.20.2.4 retrieving revision 1.1.1.3.8.11.2.20.2.5 diff -u -r1.1.1.3.8.11.2.20.2.4 -r1.1.1.3.8.11.2.20.2.5 --- squid/src/protos.h 2 May 2001 08:22:05 -0000 1.1.1.3.8.11.2.20.2.4 +++ squid/src/protos.h 7 May 2001 13:23:41 -0000 1.1.1.3.8.11.2.20.2.5 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.4 2001/05/02 08:22:05 rbcollins Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.5 2001/05/07 13:23:41 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -111,8 +111,8 @@ /* Note: Allocations is done using the cbdataAlloc macro */ extern void *cbdataInternalFree(void *p); extern int cbdataValid(const void *p); -extern void cbdataInitType(cbdata_type type, char *label, int size, FREE * free_func); -extern cbdata_type cbdataAddType(cbdata_type type, char *label, int size, FREE * free_func); +extern void cbdataInitType(cbdata_type type, char *label, int size, FREE * free_func, int freeonunlock); +extern cbdata_type cbdataAddType(cbdata_type type, char *label, int size, FREE * free_func, int freeonunlock); extern int cbdataLocked(const void *p); extern void clientdbInit(void);