]> git.ipfire.org Git - thirdparty/squid.git/blob - src/PeerPoolMgr.h
merge from trunk r13423
[thirdparty/squid.git] / src / PeerPoolMgr.h
1 #ifndef SQUID_PEERPOOLMGR_H
2 #define SQUID_PEERPOOLMGR_H
3
4 #include "base/AsyncJob.h"
5 #include "comm/forward.h"
6
7 class HttpRequest;
8 class CachePeer;
9 class CommConnectCbParams;
10
11 #if USE_OPENSSL
12 namespace Ssl
13 {
14 class PeerConnectorAnswer;
15 }
16 #endif
17
18 /// Maintains an fixed-size "standby" PconnPool for a single CachePeer.
19 class PeerPoolMgr: public AsyncJob
20 {
21 public:
22 typedef CbcPointer<PeerPoolMgr> Pointer;
23
24 // syncs mgr state whenever connection-related peer or pool state changes
25 static void Checkpoint(const Pointer &mgr, const char *reason);
26
27 explicit PeerPoolMgr(CachePeer *aPeer);
28 virtual ~PeerPoolMgr();
29
30 protected:
31 /* AsyncJob API */
32 virtual void start();
33 virtual void swanSong();
34 virtual bool doneAll() const;
35
36 /// whether the peer is still out there and in a valid state we can safely use
37 bool validPeer() const;
38
39 /// Starts new connection, or closes the excess connections
40 /// according pool configuration
41 void checkpoint(const char *reason);
42 /// starts the process of opening a new standby connection (if possible)
43 void openNewConnection();
44 /// closes 'howMany' standby connections
45 void closeOldConnections(const int howMany);
46
47 /// Comm::ConnOpener calls this when done opening a connection for us
48 void handleOpenedConnection(const CommConnectCbParams &params);
49 #if USE_OPENSSL
50 /// Ssl::PeerConnector callback
51 void handleSecuredPeer(Ssl::PeerConnectorAnswer &answer);
52 /// called when the connection we are trying to secure is closed by a 3rd party
53 void handleSecureClosure(const CommCloseCbParams &params);
54 #endif
55 /// the final step in connection opening (and, optionally, securing) sequence
56 void pushNewConnection(const Comm::ConnectionPointer &conn);
57
58 private:
59 CachePeer *peer; ///< the owner of the pool we manage
60 RefCount<HttpRequest> request; ///< fake HTTP request for conn opening code
61 AsyncCall::Pointer opener; ///< whether we are opening a connection
62 AsyncCall::Pointer securer; ///< whether we are securing a connection
63 AsyncCall::Pointer closer; ///< monitors conn while we are securing it
64 unsigned int addrUsed; ///< counter for cycling through peer addresses
65
66 CBDATA_CLASS2(PeerPoolMgr);
67 };
68
69 #endif /* SQUID_PEERPOOLMGR_H */