]> git.ipfire.org Git - thirdparty/squid.git/blame - src/PeerPoolMgr.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / PeerPoolMgr.h
CommitLineData
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
15class HttpRequest;
16class CachePeer;
17class CommConnectCbParams;
18
19#if USE_OPENSSL
e2849af8
A
20namespace Ssl
21{
22class PeerConnectorAnswer;
e8dca475
CT
23}
24#endif
25
26/// Maintains an fixed-size "standby" PconnPool for a single CachePeer.
27class PeerPoolMgr: public AsyncJob
28{
5c2f68b7
AJ
29 CBDATA_CLASS(PeerPoolMgr);
30
e8dca475
CT
31public:
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
40protected:
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 &params);
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 &params);
64#endif
65 /// the final step in connection opening (and, optionally, securing) sequence
66 void pushNewConnection(const Comm::ConnectionPointer &conn);
67
68private:
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