]>
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. | |
31 | * We currently define the end-point by the FQDN it is serving. | |
32 | */ | |
781ce8ff | 33 | class IdleConnList |
34 | { | |
781ce8ff | 35 | public: |
36 | IdleConnList(const char *key, PconnPool *parent); | |
37 | ~IdleConnList(); | |
38 | int numIdle() { return nfds; } | |
39 | ||
642a305c | 40 | int findIndex(const Comm::ConnectionPointer &conn); ///< search from the end of array |
68720ca2 | 41 | |
642a305c AJ |
42 | /** |
43 | * \retval false The connection does not currently exist in the list. | |
44 | * We seem to have hit and lost a race condition. | |
45 | * Nevermind, but MUST NOT do anything with the raw FD. | |
46 | */ | |
47 | bool remove(const Comm::ConnectionPointer &conn); | |
68720ca2 | 48 | |
642a305c AJ |
49 | void push(const Comm::ConnectionPointer &conn); |
50 | Comm::ConnectionPointer findUseable(); ///< find first from the end not pending read fd. | |
51 | void clearHandlers(const Comm::ConnectionPointer &conn); | |
781ce8ff | 52 | |
53 | private: | |
54 | static IOCB read; | |
55 | static PF timeout; | |
56 | ||
57 | public: | |
e1f7507e | 58 | hash_link hash; /** must be first */ |
781ce8ff | 59 | |
60 | private: | |
642a305c | 61 | Comm::ConnectionPointer *theList; |
781ce8ff | 62 | int nfds_alloc; |
63 | int nfds; | |
64 | PconnPool *parent; | |
642a305c | 65 | char fakeReadBuf[4096]; // TODO: kill magic number. |
781ce8ff | 66 | CBDATA_CLASS2(IdleConnList); |
67 | }; | |
68 | ||
e1f7507e | 69 | |
e06b8df8 HN |
70 | #include "ip/forward.h" |
71 | ||
e1f7507e AJ |
72 | class StoreEntry; |
73 | class IdleConnLimit; | |
74 | ||
75 | /* for hash_table */ | |
76 | #include "hash.h" | |
77 | ||
855150a4 AJ |
78 | /** \ingroup PConnAPI |
79 | * A pool of persistent connections for a particular service type. | |
80 | * HTTP servers being one such pool type, ICAP services another etc. | |
81 | */ | |
781ce8ff | 82 | class PconnPool |
83 | { | |
84 | ||
85 | public: | |
86 | PconnPool(const char *); | |
7a56c509 | 87 | ~PconnPool(); |
781ce8ff | 88 | |
89 | void moduleInit(); | |
642a305c AJ |
90 | void push(const Comm::ConnectionPointer &serverConn, const char *domain); |
91 | ||
92 | /** | |
93 | * Updates destLink to point at an existing open connection if available and retriable. | |
94 | * Otherwise, return false. | |
95 | * | |
96 | * We close available persistent connection if the caller transaction is not | |
97 | * retriable to avoid having a growing number of open connections when many | |
98 | * transactions create persistent connections but are not retriable. | |
99 | */ | |
100 | bool pop(Comm::ConnectionPointer &serverConn, const char *domain, bool retriable); | |
781ce8ff | 101 | void count(int uses); |
642a305c AJ |
102 | void dumpHist(StoreEntry *e) const; |
103 | void dumpHash(StoreEntry *e) const; | |
781ce8ff | 104 | void unlinkList(IdleConnList *list) const; |
105 | ||
106 | private: | |
107 | ||
642a305c | 108 | static const char *key(const Comm::ConnectionPointer &destLink, const char *domain); |
781ce8ff | 109 | |
110 | int hist[PCONN_HIST_SZ]; | |
111 | hash_table *table; | |
112 | const char *descr; | |
781ce8ff | 113 | }; |
114 | ||
e1f7507e | 115 | |
e1f7507e AJ |
116 | class StoreEntry; |
117 | class PconnPool; | |
118 | ||
855150a4 AJ |
119 | /** \ingroup PConnAPI |
120 | * The global registry of persistent connection pools. | |
121 | */ | |
781ce8ff | 122 | class PconnModule |
123 | { | |
124 | ||
125 | public: | |
e1f7507e | 126 | /** the module is a singleton until we have instance based cachemanager |
62ee09ca | 127 | * management |
128 | */ | |
129 | static PconnModule * GetInstance(); | |
e1f7507e | 130 | /** A thunk to the still C like CacheManager callback api. */ |
62ee09ca | 131 | static void DumpWrapper(StoreEntry *e); |
132 | ||
781ce8ff | 133 | PconnModule(); |
15fab853 | 134 | void registerWithCacheManager(void); |
781ce8ff | 135 | |
e1f7507e | 136 | void add(PconnPool *); |
781ce8ff | 137 | |
138 | OBJH dump; | |
139 | ||
140 | private: | |
141 | PconnPool **pools; | |
142 | ||
62ee09ca | 143 | static PconnModule * instance; |
144 | ||
781ce8ff | 145 | int poolCount; |
146 | }; | |
147 | ||
148 | #endif /* SQUID_PCONN_H */ |