]>
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 | ||
0c8a9718 | 40 | int findFDIndex(int fd); ///< search from the end of array |
68720ca2 AJ |
41 | |
42 | /// If false the FD does not currently exist in the list. | |
43 | /// We seem to have hit and lost a race condition. | |
44 | /// Nevermind, but MUST NOT do anything with the raw FD. | |
45 | bool removeFD(int fd); | |
46 | ||
781ce8ff | 47 | void push(int fd); |
0c8a9718 | 48 | int findUseableFD(); ///< find first from the end not pending read fd. |
781ce8ff | 49 | void clearHandlers(int fd); |
50 | ||
51 | private: | |
52 | static IOCB read; | |
53 | static PF timeout; | |
54 | ||
55 | public: | |
e1f7507e | 56 | hash_link hash; /** must be first */ |
781ce8ff | 57 | |
58 | private: | |
59 | int *fds; | |
60 | int nfds_alloc; | |
61 | int nfds; | |
62 | PconnPool *parent; | |
63 | char fakeReadBuf[4096]; | |
64 | CBDATA_CLASS2(IdleConnList); | |
65 | }; | |
66 | ||
e1f7507e | 67 | |
e06b8df8 HN |
68 | #include "ip/forward.h" |
69 | ||
e1f7507e AJ |
70 | class StoreEntry; |
71 | class IdleConnLimit; | |
72 | ||
73 | /* for hash_table */ | |
74 | #include "hash.h" | |
75 | ||
855150a4 AJ |
76 | /** \ingroup PConnAPI |
77 | * A pool of persistent connections for a particular service type. | |
78 | * HTTP servers being one such pool type, ICAP services another etc. | |
79 | */ | |
781ce8ff | 80 | class PconnPool |
81 | { | |
82 | ||
83 | public: | |
84 | PconnPool(const char *); | |
7a56c509 | 85 | ~PconnPool(); |
781ce8ff | 86 | |
87 | void moduleInit(); | |
b7ac5457 AJ |
88 | void push(int fd, const char *host, u_short port, const char *domain, Ip::Address &client_address); |
89 | int pop(const char *host, u_short port, const char *domain, Ip::Address &client_address, bool retriable); | |
781ce8ff | 90 | void count(int uses); |
91 | void dumpHist(StoreEntry *e); | |
06093389 | 92 | void dumpHash(StoreEntry *e); |
781ce8ff | 93 | void unlinkList(IdleConnList *list) const; |
94 | ||
95 | private: | |
96 | ||
b7ac5457 | 97 | static const char *key(const char *host, u_short port, const char *domain, Ip::Address &client_address); |
781ce8ff | 98 | |
99 | int hist[PCONN_HIST_SZ]; | |
100 | hash_table *table; | |
101 | const char *descr; | |
102 | ||
103 | }; | |
104 | ||
e1f7507e | 105 | |
e1f7507e AJ |
106 | class StoreEntry; |
107 | class PconnPool; | |
108 | ||
855150a4 AJ |
109 | /** \ingroup PConnAPI |
110 | * The global registry of persistent connection pools. | |
111 | */ | |
781ce8ff | 112 | class PconnModule |
113 | { | |
114 | ||
115 | public: | |
e1f7507e | 116 | /** the module is a singleton until we have instance based cachemanager |
62ee09ca | 117 | * management |
118 | */ | |
119 | static PconnModule * GetInstance(); | |
e1f7507e | 120 | /** A thunk to the still C like CacheManager callback api. */ |
62ee09ca | 121 | static void DumpWrapper(StoreEntry *e); |
122 | ||
781ce8ff | 123 | PconnModule(); |
15fab853 | 124 | void registerWithCacheManager(void); |
781ce8ff | 125 | |
e1f7507e | 126 | void add(PconnPool *); |
781ce8ff | 127 | |
128 | OBJH dump; | |
129 | ||
130 | private: | |
131 | PconnPool **pools; | |
132 | ||
62ee09ca | 133 | static PconnModule * instance; |
134 | ||
781ce8ff | 135 | int poolCount; |
136 | }; | |
137 | ||
138 | #endif /* SQUID_PCONN_H */ |