]>
Commit | Line | Data |
---|---|---|
bbc27441 AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
e8dca475 CT |
9 | #ifndef SQUID_PEERPOOLMGR_H |
10 | #define SQUID_PEERPOOLMGR_H | |
11 | ||
12 | #include "base/AsyncJob.h" | |
13 | #include "comm/forward.h" | |
14 | ||
15 | class HttpRequest; | |
16 | class CachePeer; | |
17 | class CommConnectCbParams; | |
18 | ||
19 | #if USE_OPENSSL | |
e2849af8 A |
20 | namespace Ssl |
21 | { | |
22 | class PeerConnectorAnswer; | |
e8dca475 CT |
23 | } |
24 | #endif | |
25 | ||
26 | /// Maintains an fixed-size "standby" PconnPool for a single CachePeer. | |
27 | class PeerPoolMgr: public AsyncJob | |
28 | { | |
5c2f68b7 AJ |
29 | CBDATA_CLASS(PeerPoolMgr); |
30 | ||
e8dca475 CT |
31 | public: |
32 | typedef CbcPointer<PeerPoolMgr> Pointer; | |
33 | ||
34 | // syncs mgr state whenever connection-related peer or pool state changes | |
35 | static void Checkpoint(const Pointer &mgr, const char *reason); | |
36 | ||
37 | explicit PeerPoolMgr(CachePeer *aPeer); | |
38 | virtual ~PeerPoolMgr(); | |
39 | ||
40 | protected: | |
41 | /* AsyncJob API */ | |
42 | virtual void start(); | |
43 | virtual void swanSong(); | |
44 | virtual bool doneAll() const; | |
45 | ||
46 | /// whether the peer is still out there and in a valid state we can safely use | |
47 | bool validPeer() const; | |
48 | ||
49 | /// Starts new connection, or closes the excess connections | |
50 | /// according pool configuration | |
51 | void checkpoint(const char *reason); | |
52 | /// starts the process of opening a new standby connection (if possible) | |
53 | void openNewConnection(); | |
54 | /// closes 'howMany' standby connections | |
55 | void closeOldConnections(const int howMany); | |
56 | ||
57 | /// Comm::ConnOpener calls this when done opening a connection for us | |
58 | void handleOpenedConnection(const CommConnectCbParams ¶ms); | |
59 | #if USE_OPENSSL | |
60 | /// Ssl::PeerConnector callback | |
61 | void handleSecuredPeer(Ssl::PeerConnectorAnswer &answer); | |
62 | /// called when the connection we are trying to secure is closed by a 3rd party | |
63 | void handleSecureClosure(const CommCloseCbParams ¶ms); | |
64 | #endif | |
65 | /// the final step in connection opening (and, optionally, securing) sequence | |
66 | void pushNewConnection(const Comm::ConnectionPointer &conn); | |
67 | ||
68 | private: | |
69 | CachePeer *peer; ///< the owner of the pool we manage | |
70 | RefCount<HttpRequest> request; ///< fake HTTP request for conn opening code | |
71 | AsyncCall::Pointer opener; ///< whether we are opening a connection | |
72 | AsyncCall::Pointer securer; ///< whether we are securing a connection | |
73 | AsyncCall::Pointer closer; ///< monitors conn while we are securing it | |
74 | unsigned int addrUsed; ///< counter for cycling through peer addresses | |
e8dca475 CT |
75 | }; |
76 | ||
77 | #endif /* SQUID_PEERPOOLMGR_H */ | |
f53969cc | 78 |