]> git.ipfire.org Git - thirdparty/squid.git/blame - src/pconn.h
Fixed parsing of TLS messages that span multiple records (#457)
[thirdparty/squid.git] / src / pconn.h
CommitLineData
bbc27441 1/*
f6e9a3ee 2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
bbc27441
AJ
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
781ce8ff 9#ifndef SQUID_PCONN_H
10#define SQUID_PCONN_H
11
e8dca475 12#include "base/CbcPointer.h"
a27fcaed 13#include "base/RunnersRegistry.h"
5ce18e2a
AJ
14#include "mgr/forward.h"
15
e8dca475
CT
16#include <set>
17
e1f7507e
AJ
18/**
19 \defgroup PConnAPI Persistent Connection API
20 \ingroup Component
21 *
22 \todo CLEANUP: Break multiple classes out of the generic pconn.h header
23 */
62ee09ca 24
781ce8ff 25class PconnPool;
e8dca475 26class PeerPoolMgr;
781ce8ff 27
e1f7507e 28#include "cbdata.h"
e1f7507e
AJ
29#include "hash.h"
30/* for IOCB */
31#include "comm.h"
32
e1f7507e 33/// \ingroup PConnAPI
62ee09ca 34#define PCONN_HIST_SZ (1<<16)
35
855150a4
AJ
36/** \ingroup PConnAPI
37 * A list of connections currently open to a particular destination end-point.
855150a4 38 */
a27fcaed 39class IdleConnList: public hash_link, private IndependentRunner
781ce8ff 40{
5c2f68b7
AJ
41 CBDATA_CLASS(IdleConnList);
42
781ce8ff 43public:
44 IdleConnList(const char *key, PconnPool *parent);
45 ~IdleConnList();
68720ca2 46
80463bb4 47 /// Pass control of the connection to the idle list.
642a305c 48 void push(const Comm::ConnectionPointer &conn);
139d9221 49
9815f129
AJ
50 /// get first conn which is not pending read fd.
51 Comm::ConnectionPointer pop();
781ce8ff 52
80463bb4
AJ
53 /** Search the list for a connection which matches the 'key' details
54 * and pop it off the list.
139d9221
AJ
55 * The list is created based on remote IP:port hash. This further filters
56 * the choices based on specific local-end details requested.
80463bb4 57 * If nothing usable is found the a nil pointer is returned.
139d9221
AJ
58 */
59 Comm::ConnectionPointer findUseable(const Comm::ConnectionPointer &key);
80463bb4 60
642a305c 61 void clearHandlers(const Comm::ConnectionPointer &conn);
781ce8ff 62
983983ce 63 int count() const { return size_; }
9815f129 64 void closeN(size_t count);
2dba5b8e 65
a27fcaed
CT
66 // IndependentRunner API
67 virtual void endingShutdown();
781ce8ff 68private:
a8c28b85 69 bool isAvailable(int i) const;
80463bb4
AJ
70 bool removeAt(int index);
71 int findIndexOf(const Comm::ConnectionPointer &conn) const;
a8c28b85 72 void findAndClose(const Comm::ConnectionPointer &conn);
80463bb4 73 static IOCB Read;
8d77a37c 74 static CTCB Timeout;
781ce8ff 75
781ce8ff 76private:
80463bb4 77 /** List of connections we are holding.
50847dca 78 * Sorted as FIFO list for most efficient speeds on pop() and findUsable()
80463bb4
AJ
79 * The worst-case pop() and scans occur on timeout and link closure events
80 * where timing is less critical. Occasional slow additions are okay.
81 */
e3981652 82 Comm::ConnectionPointer *theList_;
80463bb4
AJ
83
84 /// Number of entries theList can currently hold without re-allocating (capacity).
e3981652 85 int capacity_;
80463bb4 86 ///< Number of in-use entries in theList
e3981652 87 int size_;
80463bb4
AJ
88
89 /** The pool containing this sub-list.
90 * The parent performs all stats accounting, and
91 * will delete us when it dies. It persists for the
92 * full duration of our existence.
93 */
e3981652 94 PconnPool *parent_;
80463bb4 95
e3981652 96 char fakeReadBuf_[4096]; // TODO: kill magic number.
781ce8ff 97};
98
e06b8df8
HN
99#include "ip/forward.h"
100
e1f7507e
AJ
101class StoreEntry;
102class IdleConnLimit;
103
104/* for hash_table */
105#include "hash.h"
106
855150a4 107/** \ingroup PConnAPI
01eb26fc
AJ
108 * Manages idle persistent connections to a caller-defined set of
109 * servers (e.g., all HTTP servers). Uses a collection of IdleConnLists
110 * internally to list the individual open connections to each server.
111 * Controls lists existence and limits the total number of
112 * idle connections across the collection.
855150a4 113 */
781ce8ff 114class PconnPool
115{
116
117public:
e8dca475 118 PconnPool(const char *aDescription, const CbcPointer<PeerPoolMgr> &aMgr);
7a56c509 119 ~PconnPool();
781ce8ff 120
121 void moduleInit();
642a305c
AJ
122 void push(const Comm::ConnectionPointer &serverConn, const char *domain);
123
124 /**
e8dca475
CT
125 * Returns either a pointer to a popped connection to dest or nil.
126 * Closes the connection before returning its pointer unless keepOpen.
642a305c 127 *
e8dca475
CT
128 * A caller with a non-retriable transaction should set keepOpen to false
129 * and call pop() anyway, even though the caller does not want a pconn.
130 * This forces us to close an available persistent connection, avoiding
e2849af8 131 * creating a growing number of open connections when many transactions
e8dca475
CT
132 * create (and push) persistent connections but are not retriable and,
133 * hence, do not need to pop a connection.
642a305c 134 */
e8dca475 135 Comm::ConnectionPointer pop(const Comm::ConnectionPointer &dest, const char *domain, bool keepOpen);
781ce8ff 136 void count(int uses);
642a305c
AJ
137 void dumpHist(StoreEntry *e) const;
138 void dumpHash(StoreEntry *e) const;
2dba5b8e 139 void unlinkList(IdleConnList *list);
983983ce 140 void noteUses(int uses);
e8dca475
CT
141 /// closes any n connections, regardless of their destination
142 void closeN(int n);
2dba5b8e
CT
143 int count() const { return theCount; }
144 void noteConnectionAdded() { ++theCount; }
145 void noteConnectionRemoved() { assert(theCount > 0); --theCount; }
781ce8ff 146
e8dca475
CT
147 // sends an async message to the pool manager, if any
148 void notifyManager(const char *reason);
149
781ce8ff 150private:
151
642a305c 152 static const char *key(const Comm::ConnectionPointer &destLink, const char *domain);
781ce8ff 153
154 int hist[PCONN_HIST_SZ];
155 hash_table *table;
156 const char *descr;
e8dca475 157 CbcPointer<PeerPoolMgr> mgr; ///< optional pool manager (for notifications)
2dba5b8e 158 int theCount; ///< the number of pooled connections
781ce8ff 159};
160
e1f7507e
AJ
161class StoreEntry;
162class PconnPool;
163
855150a4
AJ
164/** \ingroup PConnAPI
165 * The global registry of persistent connection pools.
166 */
781ce8ff 167class PconnModule
168{
169
170public:
e1f7507e 171 /** the module is a singleton until we have instance based cachemanager
62ee09ca 172 * management
173 */
174 static PconnModule * GetInstance();
e1f7507e 175 /** A thunk to the still C like CacheManager callback api. */
62ee09ca 176 static void DumpWrapper(StoreEntry *e);
177
781ce8ff 178 PconnModule();
15fab853 179 void registerWithCacheManager(void);
781ce8ff 180
e1f7507e 181 void add(PconnPool *);
e8dca475 182 void remove(PconnPool *); ///< unregister and forget about this pool object
781ce8ff 183
184 OBJH dump;
185
186private:
e8dca475
CT
187 typedef std::set<PconnPool*> Pools; ///< unordered PconnPool collection
188 Pools pools; ///< all live pools
781ce8ff 189
62ee09ca 190 static PconnModule * instance;
781ce8ff 191};
192
193#endif /* SQUID_PCONN_H */
f53969cc 194