]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Pipeline.h
Add class Pipeline with API for handling client request pipelines
[thirdparty/squid.git] / src / Pipeline.h
CommitLineData
8e64903f
AJ
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#ifndef SQUID_SRC_PIPELINE_H
10#define SQUID_SRC_PIPELINE_H
11
12#include "base/RefCount.h"
13
14#include <list>
15
16class ClientSocketContext;
17typedef RefCount<ClientSocketContext> ClientSocketContextPointer;
18
19/**
20 * A queue of requests awaiting completion.
21 *
22 * Requests 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 *
28 * - HTTP/2 multiplexed streams (aka requests) can be processed
29 * and delivered in any order.
30 *
31 * For consistency we treat the pipeline as a FIFO queue in both cases.
32 */
33class Pipeline
34{
35 Pipeline(const Pipeline &) = delete;
36 Pipeline & operator =(const Pipeline &) = delete;
37
38public:
39 Pipeline() : nrequests(0) {}
40 ~Pipeline() {terminateAll(0);}
41
42 /// register a new request context to the pipeline
43 void add(const ClientSocketContextPointer &);
44
45 /// get the first request context in the pipeline
46 ClientSocketContextPointer front() const;
47
48 /// how many requests are currently pipelined
49 size_t count() const {return requests.size();}
50
51 /// whether there are none or any requests currently pipelined
52 bool empty() const {return requests.empty();}
53
54 /// tell everybody about the err, and abort all waiting requests
55 void terminateAll(const int xerrno);
56
57 /// deregister the front request from the pipeline
58 void pop();
59
60 /// Number of requests seen in this pipeline (so far).
61 /// Includes incomplete transactions.
62 uint32_t nrequests;
63
64private:
65 /// requests parsed from the connection but not yet completed.
66 std::list<ClientSocketContextPointer> requests;
67};
68
69#endif /* SQUID_SRC_PIPELINE_H */
70