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