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