--------------------- PatchSet 5260 Date: 2002/10/06 11:32:06 Author: rbcollins Branch: commloops Tag: (none) Log: more extractions Members: src/client_side.c:1.52.4.12->1.52.4.13 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.52.4.12 retrieving revision 1.52.4.13 diff -u -r1.52.4.12 -r1.52.4.13 --- squid/src/client_side.c 6 Oct 2002 10:20:26 -0000 1.52.4.12 +++ squid/src/client_side.c 6 Oct 2002 11:32:06 -0000 1.52.4.13 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.52.4.12 2002/10/06 10:20:26 rbcollins Exp $ + * $Id: client_side.c,v 1.52.4.13 2002/10/06 11:32:06 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1300,10 +1300,47 @@ } static void -clientProcessRequest(ConnStateData *conn, clientSocketContext *context, request_t *request) +clientProcessRequest(ConnStateData *conn, clientSocketContext *context, method_t method, char *prefix, size_t req_line_sz) { clientHttpRequest *http = context->http; + request_t *request = NULL; + /* We have an initial client stream in place should it be needed */ + /* setup our private context */ + connNoteUseOfBuffer(conn, http->req_sz); + + connAddContextToQueue(conn, context); + if (context->flags.parsed_ok == 0) { + clientStreamNode *node = getClientReplyContext(context); + debug(33, 1) ("clientReadRequest: Invalid Request\n"); + clientSetReplyToError(node->data, + ERR_INVALID_REQ, HTTP_BAD_REQUEST, method, NULL, + &conn->peer.sin_addr, NULL, conn->in.buf, NULL); + assert(context->http->out.offset == 0); + clientPullData(context); + conn->flags.readMoreRequests = 0; + return; + } + + if ((request = urlParse(method, http->uri)) == NULL) { + clientStreamNode *node = getClientReplyContext(context); + debug(33, 5) ("Invalid URL: %s\n", http->uri); + clientSetReplyToError(node->data, + ERR_INVALID_URL, HTTP_BAD_REQUEST, method, http->uri, + &conn->peer.sin_addr, NULL, NULL, NULL); + assert(context->http->out.offset == 0); + clientPullData(context); + conn->flags.readMoreRequests = 0; + return; + } else { + /* compile headers */ + /* we should skip request line! */ + if (!httpRequestParseHeader(request, prefix + req_line_sz)) + debug(33, 1) ("Failed to parse request headers: %s\n%s\n", + http->uri, prefix); + /* continue anyway? */ + } + request->flags.accelerated = http->flags.accel; if (!http->flags.internal) { if (internalCheck(strBuf(request->urlpath))) { @@ -1381,16 +1418,38 @@ clientAccessCheck(http); } +static void +connStripBufferWhitespace (ConnStateData *conn) +{ + while (conn->in.notYetUsed > 0 && xisspace(conn->in.buf[0])) { + xmemmove(conn->in.buf, conn->in.buf + 1, conn->in.notYetUsed - 1); + --conn->in.notYetUsed; + } +} + +static int +connOkToAddRequest(ConnStateData *conn) +{ + int result = connGetConcurrentRequestCount(conn) < (Config.onoff.pipeline_prefetch ? 2 : 1); + if (!result) { + debug(33, 3) ("clientReadRequest: FD %d max concurrent requests reached\n", + conn->fd); + debug(33, 5) ("clientReadRequest: FD %d defering new request until one is done\n", + conn->fd); + } + return result; +} + static void clientReadRequest(int fd, char *buf, size_t size, comm_err_t flag, int xerrno, void *data) { ConnStateData *conn = data; method_t method; char *prefix = NULL; - fde *F = &fd_table[fd]; clientSocketContext *context; int do_next_read = 1; /* the default _is_ to read data! - adrian */ + assert (fd == conn->fd); /* * Don't reset the timeout value here. The timeout value will be * set to Config.Timeout.request by httpAccept() and @@ -1410,7 +1469,7 @@ } /* It might be half-closed, we can't tell */ debug(33, 5) ("clientReadRequest: FD %d closed?\n", fd); - F->flags.socket_eof = 1; + fd_table[fd].flags.socket_eof = 1; conn->defer.until = squid_curtime + 1; conn->defer.n++; fd_note(fd, "half-closed"); @@ -1433,25 +1492,20 @@ while (conn->in.notYetUsed > 0 && conn->body.size_left == 0) { size_t req_line_sz; - /* Skip leading ( or trail from previous request) whitespace */ - while (conn->in.notYetUsed > 0 && xisspace(conn->in.buf[0])) { - xmemmove(conn->in.buf, conn->in.buf + 1, conn->in.notYetUsed - 1); - --conn->in.notYetUsed; + connStripBufferWhitespace (conn); + if (conn->in.notYetUsed == 0) { + clientAfterReadingRequests(fd, conn, do_next_read); + return; } - conn->in.buf[conn->in.notYetUsed] = '\0'; /* Terminate the string */ - if (conn->in.notYetUsed == 0) - break; /* conn->in.notYetUsed > 0 && conn->body.size_left == 0 */ /* Limit the number of concurrent requests to 2 */ - if (connGetConcurrentRequestCount(conn) >= (Config.onoff.pipeline_prefetch ? 2 : 1)) { - debug(33, 3) ("clientReadRequest: FD %d max concurrent requests reached\n", - fd); - debug(33, 5) ("clientReadRequest: FD %d defering new request until one is done\n", - fd); - conn->defer.until = squid_curtime + 100; /* Reset when a request is complete */ + if (!connOkToAddRequest(conn)) { + /* Reset when a request is complete */ + conn->defer.until = squid_curtime + 100; conn->defer.n++; clientMaybeReadData (conn, do_next_read); return; } + /* Should not be needed anymore */ conn->in.buf[conn->in.notYetUsed] = '\0'; /* Terminate the string */ /* Process request */ context = parseHttpRequest(conn, @@ -1466,47 +1520,12 @@ /* status -1 or 1 */ if (context) { - clientHttpRequest *http = context->http; - request_t *request = NULL; - /* We have an initial client stream in place should it be needed */ - /* setup our private context */ - connNoteUseOfBuffer(conn, http->req_sz); - - connAddContextToQueue(conn, context); commSetTimeout(fd, Config.Timeout.lifetime, clientLifetimeTimeout, - http); - if (context->flags.parsed_ok == 0) { - clientStreamNode *node = getClientReplyContext(context); - debug(33, 1) ("clientReadRequest: FD %d Invalid Request\n", fd); - clientSetReplyToError(node->data, - ERR_INVALID_REQ, HTTP_BAD_REQUEST, method, NULL, - &conn->peer.sin_addr, NULL, conn->in.buf, NULL); - assert(context->http->out.offset == 0); - clientPullData(context); - safe_free(prefix); - break; - } - if ((request = urlParse(method, http->uri)) == NULL) { - clientStreamNode *node = getClientReplyContext(context); - debug(33, 5) ("Invalid URL: %s\n", http->uri); - clientSetReplyToError(node->data, - ERR_INVALID_URL, HTTP_BAD_REQUEST, method, http->uri, - &conn->peer.sin_addr, NULL, NULL, NULL); - assert(context->http->out.offset == 0); - clientPullData(context); - safe_free(prefix); - break; - } else { - /* compile headers */ - /* we should skip request line! */ - if (!httpRequestParseHeader(request, prefix + req_line_sz)) - debug(33, 1) ("Failed to parse request headers: %s\n%s\n", - http->uri, prefix); - /* continue anyway? */ - } - safe_free(prefix); + context->http); - clientProcessRequest(conn, context, request); + clientProcessRequest(conn, context, method, prefix, req_line_sz); + + safe_free(prefix); if (!conn->flags.readMoreRequests) { conn->flags.readMoreRequests = 1; break;