--------------------- PatchSet 5028 Date: 2002/09/17 22:09:43 Author: rbcollins Branch: fixrange Tag: (none) Log: factor pass through and serialisation out of clientSocketRecipient Members: src/client_side.c:1.72.2.20->1.72.2.21 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.72.2.20 retrieving revision 1.72.2.21 diff -u -r1.72.2.20 -r1.72.2.21 --- squid/src/client_side.c 17 Sep 2002 21:51:22 -0000 1.72.2.20 +++ squid/src/client_side.c 17 Sep 2002 22:09:43 -0000 1.72.2.21 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.72.2.20 2002/09/17 21:51:22 rbcollins Exp $ + * $Id: client_side.c,v 1.72.2.21 2002/09/17 22:09:43 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -98,6 +98,7 @@ HttpReply *rep; StoreIOBuffer queuedBuffer; } deferredparams; + off_t writtenToSocket; } clientSocketContext; CBDATA_TYPE(clientSocketContext); @@ -144,7 +145,10 @@ static int connIsUsable(ConnStateData *conn); static clientSocketContext *connGetCurrentContext(ConnStateData *conn); static void contextDeferRecipientForLater(clientSocketContext *context, clientStreamNode * node, HttpReply * rep, StoreIOBuffer recievedData); - +static int responseFinishedOrFailed(HttpReply * rep, StoreIOBuffer recievedData); +static int contextStartOfOutput(clientSocketContext *context); +static void contextSendBody(clientSocketContext *context, HttpReply * rep,StoreIOBuffer bodyData); +static void contextSendStartOfMessage(clientSocketContext *context, HttpReply * rep,StoreIOBuffer bodyData); clientStreamNode * getTail (clientSocketContext *context) @@ -549,6 +553,49 @@ return 0; } +int +contextStartOfOutput(clientSocketContext *context) +{ + return context->http->out.offset == 0 ? 1 : 0; +} + +void +contextSendBody(clientSocketContext *context, HttpReply * rep,StoreIOBuffer bodyData) +{ + assert(rep == NULL); + context->http->out.offset += bodyData.length; + comm_write(context->http->conn->fd, bodyData.data, bodyData.length, + clientWriteBodyComplete, context, + NULL); + return; +} + +void +contextSendStartOfMessage(clientSocketContext *context, HttpReply * rep,StoreIOBuffer bodyData) +{ + MemBuf mb; + /* write headers and/or body if any */ + assert(rep || ( bodyData.data && bodyData.length)); + /* init mb; put status line and headers if any */ + if (rep) { + mb = httpReplyPack(rep); +#if HEADERS_LOG + headersLog(0, 0, context->http->request->method, rep); +#endif + httpReplyDestroy(rep); + rep = NULL; + } else { + memBufDefInit(&mb); + } + if (bodyData.data && bodyData.length) { + context->http->out.offset += bodyData.length; + memBufAppend(&mb, bodyData.data, bodyData.length); + } + /* write */ + comm_write_mbuf(context->http->conn->fd, mb, clientWriteComplete, context); + /* if we don't do it, who will? */ +} + /* * Write a chunk of data to a client socket. If the reply is present, send the reply headers down the wire too, * and clean them up when finished. @@ -580,45 +627,14 @@ contextDeferRecipientForLater (context, node, rep, recievedData); return; } - /* EOF / Read error / aborted entry */ if (responseFinishedOrFailed(rep, recievedData)) { clientWriteComplete(fd, NULL, 0, COMM_OK, context); return; } - /* trivial case */ - if (http->out.offset != 0) { - assert(rep == NULL); - /* Avoid copying to MemBuf if we know "rep" is NULL, - * and we only have a body */ - http->out.offset += recievedData.length; - comm_write(fd, recievedData.data, recievedData.length, clientWriteBodyComplete, context, - NULL); - /* NULL because its a static buffer */ - return; - } else { - MemBuf mb; - /* write headers and/or body if any */ - assert(rep || ( recievedData.data && recievedData.length)); - /* init mb; put status line and headers if any */ - if (rep) { - mb = httpReplyPack(rep); -/* http->out.offset += rep->hdr_sz; */ -#if HEADERS_LOG - headersLog(0, 0, http->request->method, rep); -#endif - httpReplyDestroy(rep); - rep = NULL; - } else { - memBufDefInit(&mb); - } - if ( recievedData.data && recievedData.length) { - http->out.offset += recievedData.length; - memBufAppend(&mb, recievedData.data, recievedData.length); - } - /* write */ - comm_write_mbuf(fd, mb, clientWriteComplete, context); - /* if we don't do it, who will? */ - } + if (!contextStartOfOutput (context)) + contextSendBody (context, rep, recievedData); + else + contextSendStartOfMessage (context, rep, recievedData); } /* Called when a downstream node is no longer interested in @@ -631,7 +647,8 @@ clientSocketContext *context; /* Test preconditions */ assert(node != NULL); - /* TODO: handle this rather than asserting - it should only ever happen if we cause an abort and + /* TODO: handle this rather than asserting + * - it should only ever happen if we cause an abort and * the callback chain loops back to here, so we can simply return. * However, that itself shouldn't happen, so it stays as an assert for now. */