]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Pipeline.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Pipeline.h
1 /*
2 * Copyright (C) 1996-2016 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 #ifndef SQUID_SRC_PIPELINE_H
10 #define SQUID_SRC_PIPELINE_H
11
12 #include "base/RefCount.h"
13
14 #include <list>
15
16 class ClientSocketContext;
17 typedef RefCount<ClientSocketContext> ClientSocketContextPointer;
18
19 /**
20 * A queue of transactions awaiting completion.
21 *
22 * Transactions in the queue may be fully processed, but not yet delivered,
23 * or only partially processed.
24 *
25 * - HTTP/1 pipelined requests can be processed out of order but
26 * responses MUST be written to the client in-order.
27 * The front() context is for the response writing transaction.
28 * The back context may still be reading a request payload/body.
29 * Other contexts are in deferred I/O state, but may be accumulating
30 * payload/body data to be written later.
31 *
32 * - HTTP/2 multiplexed streams can be processed and delivered in any order.
33 *
34 * For consistency we treat the pipeline as a FIFO queue in both cases.
35 */
36 class Pipeline
37 {
38 Pipeline(const Pipeline &) = delete;
39 Pipeline & operator =(const Pipeline &) = delete;
40
41 public:
42 Pipeline() : nrequests(0) {}
43 ~Pipeline() = default;
44
45 /// register a new request context to the pipeline
46 void add(const ClientSocketContextPointer &);
47
48 /// get the first request context in the pipeline
49 ClientSocketContextPointer front() const;
50
51 /// how many requests are currently pipelined
52 size_t count() const {return requests.size();}
53
54 /// whether there are none or any requests currently pipelined
55 bool empty() const {return requests.empty();}
56
57 /// tell everybody about the err, and abort all waiting requests
58 void terminateAll(const int xerrno);
59
60 /// deregister the front request from the pipeline
61 void popMe(const ClientSocketContextPointer &);
62
63 /// Number of requests seen in this pipeline (so far).
64 /// Includes incomplete transactions.
65 uint32_t nrequests;
66
67 private:
68 /// requests parsed from the connection but not yet completed.
69 std::list<ClientSocketContextPointer> requests;
70 };
71
72 #endif /* SQUID_SRC_PIPELINE_H */
73