]>
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(); | |
80463bb4 | 37 | int numIdle() const { return nfds; } |
68720ca2 | 38 | |
80463bb4 | 39 | /// Pass control of the connection to the idle list. |
642a305c | 40 | void push(const Comm::ConnectionPointer &conn); |
139d9221 | 41 | |
80463bb4 AJ |
42 | /** Search the list for a connection which matches the 'key' details |
43 | * and pop it off the list. | |
139d9221 AJ |
44 | * The list is created based on remote IP:port hash. This further filters |
45 | * the choices based on specific local-end details requested. | |
80463bb4 | 46 | * If nothing usable is found the a nil pointer is returned. |
139d9221 AJ |
47 | */ |
48 | Comm::ConnectionPointer findUseable(const Comm::ConnectionPointer &key); | |
80463bb4 | 49 | |
642a305c | 50 | void clearHandlers(const Comm::ConnectionPointer &conn); |
781ce8ff | 51 | |
52 | private: | |
80463bb4 AJ |
53 | bool removeAt(int index); |
54 | int findIndexOf(const Comm::ConnectionPointer &conn) const; | |
55 | static IOCB Read; | |
56 | static PF Timeout; | |
781ce8ff | 57 | |
58 | public: | |
e1f7507e | 59 | hash_link hash; /** must be first */ |
781ce8ff | 60 | |
61 | private: | |
80463bb4 AJ |
62 | /** List of connections we are holding. |
63 | * Sorted oldest to newest for most efficient speeds on pop() and findUsable() | |
64 | * The worst-case pop() and scans occur on timeout and link closure events | |
65 | * where timing is less critical. Occasional slow additions are okay. | |
66 | */ | |
642a305c | 67 | Comm::ConnectionPointer *theList; |
80463bb4 AJ |
68 | |
69 | /// Number of entries theList can currently hold without re-allocating (capacity). | |
781ce8ff | 70 | int nfds_alloc; |
80463bb4 | 71 | ///< Number of in-use entries in theList |
781ce8ff | 72 | int nfds; |
80463bb4 AJ |
73 | |
74 | /** The pool containing this sub-list. | |
75 | * The parent performs all stats accounting, and | |
76 | * will delete us when it dies. It persists for the | |
77 | * full duration of our existence. | |
78 | */ | |
781ce8ff | 79 | PconnPool *parent; |
80463bb4 | 80 | |
642a305c | 81 | char fakeReadBuf[4096]; // TODO: kill magic number. |
80463bb4 | 82 | |
781ce8ff | 83 | CBDATA_CLASS2(IdleConnList); |
84 | }; | |
85 | ||
e1f7507e | 86 | |
e06b8df8 HN |
87 | #include "ip/forward.h" |
88 | ||
e1f7507e AJ |
89 | class StoreEntry; |
90 | class IdleConnLimit; | |
91 | ||
92 | /* for hash_table */ | |
93 | #include "hash.h" | |
94 | ||
855150a4 AJ |
95 | /** \ingroup PConnAPI |
96 | * A pool of persistent connections for a particular service type. | |
97 | * HTTP servers being one such pool type, ICAP services another etc. | |
98 | */ | |
781ce8ff | 99 | class PconnPool |
100 | { | |
101 | ||
102 | public: | |
103 | PconnPool(const char *); | |
7a56c509 | 104 | ~PconnPool(); |
781ce8ff | 105 | |
106 | void moduleInit(); | |
642a305c AJ |
107 | void push(const Comm::ConnectionPointer &serverConn, const char *domain); |
108 | ||
109 | /** | |
110 | * Updates destLink to point at an existing open connection if available and retriable. | |
111 | * Otherwise, return false. | |
112 | * | |
113 | * We close available persistent connection if the caller transaction is not | |
114 | * retriable to avoid having a growing number of open connections when many | |
115 | * transactions create persistent connections but are not retriable. | |
116 | */ | |
80463bb4 | 117 | Comm::ConnectionPointer pop(const Comm::ConnectionPointer &destLink, const char *domain, bool retriable); |
781ce8ff | 118 | void count(int uses); |
642a305c AJ |
119 | void dumpHist(StoreEntry *e) const; |
120 | void dumpHash(StoreEntry *e) const; | |
781ce8ff | 121 | void unlinkList(IdleConnList *list) const; |
122 | ||
123 | private: | |
124 | ||
642a305c | 125 | static const char *key(const Comm::ConnectionPointer &destLink, const char *domain); |
781ce8ff | 126 | |
127 | int hist[PCONN_HIST_SZ]; | |
128 | hash_table *table; | |
129 | const char *descr; | |
781ce8ff | 130 | }; |
131 | ||
e1f7507e | 132 | |
e1f7507e AJ |
133 | class StoreEntry; |
134 | class PconnPool; | |
135 | ||
855150a4 AJ |
136 | /** \ingroup PConnAPI |
137 | * The global registry of persistent connection pools. | |
138 | */ | |
781ce8ff | 139 | class PconnModule |
140 | { | |
141 | ||
142 | public: | |
e1f7507e | 143 | /** the module is a singleton until we have instance based cachemanager |
62ee09ca | 144 | * management |
145 | */ | |
146 | static PconnModule * GetInstance(); | |
e1f7507e | 147 | /** A thunk to the still C like CacheManager callback api. */ |
62ee09ca | 148 | static void DumpWrapper(StoreEntry *e); |
149 | ||
781ce8ff | 150 | PconnModule(); |
15fab853 | 151 | void registerWithCacheManager(void); |
781ce8ff | 152 | |
e1f7507e | 153 | void add(PconnPool *); |
781ce8ff | 154 | |
155 | OBJH dump; | |
156 | ||
157 | private: | |
158 | PconnPool **pools; | |
159 | ||
62ee09ca | 160 | static PconnModule * instance; |
161 | ||
781ce8ff | 162 | int poolCount; |
163 | }; | |
164 | ||
165 | #endif /* SQUID_PCONN_H */ |