--------------------- PatchSet 10398 Date: 2008/01/14 04:51:33 Author: adri Branch: s27_adri Tag: (none) Log: Break out a large part of the conn->in buffer management. Members: src/client_side.c:1.202.2.9.4.32->1.202.2.9.4.33 src/protos.h:1.146.2.4.4.35->1.146.2.4.4.36 src/ssl.c:1.31.6.2.4.1->1.31.6.2.4.2 src/structs.h:1.158.2.5.4.15->1.158.2.5.4.16 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.32 retrieving revision 1.202.2.9.4.33 diff -u -r1.202.2.9.4.32 -r1.202.2.9.4.33 --- squid/src/client_side.c 13 Jan 2008 15:44:05 -0000 1.202.2.9.4.32 +++ squid/src/client_side.c 14 Jan 2008 04:51:33 -0000 1.202.2.9.4.33 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.32 2008/01/13 15:44:05 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.33 2008/01/14 04:51:33 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -167,6 +167,48 @@ static StoreEntry *clientCreateStoreEntry(clientHttpRequest *, method_t, request_flags); static inline int clientNatLookup(ConnStateData * conn); +/* + * conn.in buffer management stuff + */ +void +clientConnBufSetup(ConnInBuf *in, int size) +{ + in->size = size; + in->offset = 0; + in->buf = memAllocBuf(size, &in->size); +} + +void +clientConnBufFree(ConnInBuf *in) +{ + memFreeBuf(in->size, in->buf); + in->size = in->offset = 0; + in->buf = NULL; +} + +void +clientConnBufGrow(ConnInBuf *in, int newsize) +{ + in->buf = memReallocBuf(in->buf, newsize, &in->size); + debug(33, 2) ("growing request buffer: offset=%ld size=%ld\n", + (long) in->offset, (long) in->size); +} + +void +clientConnBufConsume(ConnInBuf *in, int cbytes) +{ + in->offset -= cbytes; + debug(33, 5) ("removing %d bytes; conn->in.offset = %d\n", (int) cbytes, (int) in->offset); + if (in->offset > 0) + xmemmove(in->buf, in->buf + cbytes, in->offset); +} + +void +clientConnBufCopy(ConnInBuf *in, char *dst, int numbytes) +{ + +} + /* Temporary here while restructuring stuff */ static void storeClientCopyHeadersCB(void *data, mem_node_ref nr, ssize_t size) @@ -1306,7 +1348,7 @@ authenticateAuthUserRequestUnlock(connState->auth_user_request); connState->auth_user_request = NULL; authenticateOnCloseConnection(connState); - memFreeBuf(connState->in.size, connState->in.buf); + clientConnBufFree(&connState->in); pconnHistCount(0, connState->nrequests); if (connState->pinning.fd >= 0) comm_close(connState->pinning.fd); @@ -4117,9 +4159,7 @@ debug(33, 4) ("clientReadRequest: FD %d: reading request...\n", fd); if (len == 0) { /* Grow the request memory area to accomodate for a large request */ - conn->in.buf = memReallocBuf(conn->in.buf, conn->in.size * 2, &conn->in.size); - debug(33, 2) ("growing request buffer: offset=%ld size=%ld\n", - (long) conn->in.offset, (long) conn->in.size); + clientConnBufGrow(&conn->in, conn->in.size * 2); len = conn->in.size - conn->in.offset - 1; } statCounter.syscalls.sock.reads++; @@ -4201,10 +4241,7 @@ if (cbytes > 0) { /* If we read past the end of this request, move the remaining data to the beginning */ assert(conn->in.offset >= cbytes); - conn->in.offset -= cbytes; - debug(33, 5) ("removing %d bytes; conn->in.offset = %d\n", (int) cbytes, (int) conn->in.offset); - if (conn->in.offset > 0) - xmemmove(conn->in.buf, conn->in.buf + cbytes, conn->in.offset); + clientConnBufConsume(&conn->in, cbytes); } if (chttp) @@ -4320,16 +4357,16 @@ size = conn->body.size_left; if (size > conn->body.bufsize) /* don't copy more than requested */ size = conn->body.bufsize; + + /* If this callback is valid then copy the data in */ if (valid && buf) - xmemcpy(buf, conn->in.buf, size); + clientConnBufCopy(&conn->in, buf, size); + /* regardless of whether its valid or not, consume the data */ + clientConnBufConsume(&conn->in, size); conn->body.size_left -= size; - /* Move any remaining data */ - conn->in.offset -= size; /* Resume the fd if necessary */ if (conn->in.offset < conn->in.size - 1) commResumeFD(conn->fd); - if (conn->in.offset > 0) - xmemmove(conn->in.buf, conn->in.buf + size, conn->in.offset); /* Remove request link if this is the last part of the body, as * clientReadRequest automatically continues to process next request */ if (conn->body.size_left <= 0 && request != NULL) { @@ -4629,7 +4666,7 @@ connState->me = me; connState->fd = fd; connState->pinning.fd = -1; - connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &connState->in.size); + clientConnBufSetup(&connState->in, CLIENT_REQ_BUF_SZ); comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); @@ -4789,7 +4826,7 @@ connState->me = me; connState->fd = fd; connState->pinning.fd = -1; - connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &connState->in.size); + clientConnBufSetup(&connState->in, CLIENT_REQ_BUF_SZ); comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.35 retrieving revision 1.146.2.4.4.36 diff -u -r1.146.2.4.4.35 -r1.146.2.4.4.36 --- squid/src/protos.h 6 Jan 2008 09:19:53 -0000 1.146.2.4.4.35 +++ squid/src/protos.h 14 Jan 2008 04:51:34 -0000 1.146.2.4.4.36 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.35 2008/01/06 09:19:53 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.36 2008/01/14 04:51:34 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1416,6 +1416,12 @@ extern const char *xinet_ntoa(const struct in_addr addr); /* client_side.c */ +extern void clientConnBufSetup(ConnInBuf *in, int size); +extern void clientConnBufFree(ConnInBuf *in); +extern void clientConnBufGrow(ConnInBuf *in, int newsize); +extern void clientConnBufConsume(ConnInBuf *in, int consume); +extern void clientConnBufCopy(ConnInBuf *in, char *dst, int numbytes); + extern aclCheck_t *clientAclChecklistCreate(const acl_access * acl, const clientHttpRequest * http); extern void clientInterpretRequestHeaders(clientHttpRequest * http); extern void clientAccessCheck2(void *data); Index: squid/src/ssl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ssl.c,v retrieving revision 1.31.6.2.4.1 retrieving revision 1.31.6.2.4.2 diff -u -r1.31.6.2.4.1 -r1.31.6.2.4.2 --- squid/src/ssl.c 22 Dec 2007 14:32:13 -0000 1.31.6.2.4.1 +++ squid/src/ssl.c 14 Jan 2008 04:51:35 -0000 1.31.6.2.4.2 @@ -1,6 +1,6 @@ /* - * $Id: ssl.c,v 1.31.6.2.4.1 2007/12/22 14:32:13 adri Exp $ + * $Id: ssl.c,v 1.31.6.2.4.2 2008/01/14 04:51:35 adri Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -561,8 +561,9 @@ safe_free(sslState->client.buf); sslState->client.buf = xmalloc(sslState->client.len); } - memcpy(sslState->client.buf, http->conn->in.buf, sslState->client.len); - http->conn->in.offset = 0; + clientConnBufCopy(&http->conn->in, sslState->client.buf, sslState->client.len); + clientConnBufConsume(&http->conn->in, sslState->client.len); + assert(http->conn->in.offset == 0); } comm_add_close_handler(sslState->server.fd, sslServerClosed, Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.158.2.5.4.15 retrieving revision 1.158.2.5.4.16 diff -u -r1.158.2.5.4.15 -r1.158.2.5.4.16 --- squid/src/structs.h 6 Jan 2008 09:19:54 -0000 1.158.2.5.4.15 +++ squid/src/structs.h 14 Jan 2008 04:51:35 -0000 1.158.2.5.4.16 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.158.2.5.4.15 2008/01/06 09:19:54 adri Exp $ + * $Id: structs.h,v 1.158.2.5.4.16 2008/01/14 04:51:35 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1214,13 +1214,16 @@ int is_modified; }; -struct _ConnStateData { - int fd; - struct { +struct _ConnInBuf { char *buf; size_t offset; size_t size; - } in; +}; +typedef struct _ConnInBuf ConnInBuf; + +struct _ConnStateData { + int fd; + ConnInBuf in; struct { squid_off_t size_left; /* How much body left to process */ request_t *request; /* Parameters passed to clientReadBody */