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