--------------------- PatchSet 5040 Date: 2002/09/19 03:44:52 Author: rbcollins Branch: fixrange Tag: (none) Log: extract conn buffer size logic from readRequest Members: src/client_side.c:1.72.2.32->1.72.2.33 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.72.2.32 retrieving revision 1.72.2.33 diff -u -r1.72.2.32 -r1.72.2.33 --- squid/src/client_side.c 18 Sep 2002 22:17:07 -0000 1.72.2.32 +++ squid/src/client_side.c 19 Sep 2002 03:44:52 -0000 1.72.2.33 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.72.2.32 2002/09/18 22:17:07 rbcollins Exp $ + * $Id: client_side.c,v 1.72.2.33 2002/09/19 03:44:52 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -161,6 +161,8 @@ static void prepareInternalUrl(clientHttpRequest *http, char *url); static void prepareForwardProxyUrl(clientHttpRequest *http, char *url); static void prepareAcceleratedUrl(clientHttpRequest *http, char *url, char *req_hdr); +static int connGetAvailableBufferLength (ConnStateData const *conn); +static void connMakeSpaceAvailable (ConnStateData *conn); clientStreamNode * getTail (clientSocketContext *context) @@ -1143,6 +1145,22 @@ return conn->defer.until > squid_curtime; } +int +connGetAvailableBufferLength (ConnStateData const *conn) +{ + return conn->in.size - conn->in.offset; +} + +void +connMakeSpaceAvailable (ConnStateData *conn) +{ + if (connGetAvailableBufferLength(conn) < 2) { + 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); + } +} + static void clientReadRequest(int fd, void *data) { @@ -1153,24 +1171,15 @@ method_t method; char *prefix = NULL; fde *F = &fd_table[fd]; - int len = conn->in.size - conn->in.offset - 1; + int len; clientSocketContext *context; debug(33, 4) ("clientReadRequest: FD %d: reading request...\n", fd); + connMakeSpaceAvailable(conn); + len = connGetAvailableBufferLength(conn) - 1; commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, conn, 0); - 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); - len = conn->in.size - conn->in.offset - 1; - } statCounter.syscalls.sock.reads++; + /* TODO: read should callback */ size = FD_READ_METHOD(fd, conn->in.buf + conn->in.offset, len); - if (size > 0) { - fd_bytes(fd, size, FD_READ); - kb_incr(&statCounter.client_http.kbytes_in, size); - } /* * Don't reset the timeout value here. The timeout value will be * set to Config.Timeout.request by httpAccept() and @@ -1179,6 +1188,8 @@ * lame half-close detection */ if (size > 0) { + fd_bytes(fd, size, FD_READ); + kb_incr(&statCounter.client_http.kbytes_in, size); conn->in.offset += size; conn->in.buf[conn->in.offset] = '\0'; /* Terminate the string */ } else if (size == 0) {