]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Message.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / Message.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 93 Adaptation */
10
11 #include "squid.h"
12 #include "adaptation/Message.h"
13 #include "base/TextException.h"
14 #include "HttpMsg.h"
15
16 Adaptation::Message::Message(): header(NULL)
17 {
18 }
19
20 Adaptation::Message::Message(Header *aHeader): header(NULL)
21 {
22 set(aHeader);
23 }
24
25 Adaptation::Message::~Message()
26 {
27 clear();
28 }
29
30 void
31 Adaptation::Message::clear()
32 {
33 HTTPMSGUNLOCK(header);
34 body_pipe = NULL;
35 }
36
37 void
38 Adaptation::Message::set(Header *aHeader)
39 {
40 clear();
41 if (aHeader) {
42 header = aHeader;
43 HTTPMSGLOCK(header);
44 body_pipe = header->body_pipe;
45 }
46 }
47
48 void
49 Adaptation::Message::ShortCircuit(Message &src, Message &dest)
50 {
51 Must(!dest.header); // the message is not "used"
52 Must(!dest.body_pipe); // can relax if needed, but need !body_pipe->used()
53 Must(src.header); // or there is nothing to shortcircuit
54
55 if (src.header->body_pipe != NULL) {
56 // check that it would not be too late to shortcircuit the pipe
57 Must(!src.header->body_pipe->consumedSize());
58 src.header->body_pipe->clearConsumer(); // if any
59 // note: current header->body_pipe producer may later become
60 // dest.body_pipe consumer and consume its own data
61 // TODO: consumer should detect and bypass short-circuit adaptation
62 }
63 dest.set(src.header->clone());
64 }
65