]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Coordinator.h
Merge from trunk rev.13866
[thirdparty/squid.git] / src / ipc / Coordinator.h
1 /*
2 * Copyright (C) 1996-2015 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
9 /* DEBUG: section 54 Interprocess Communication */
10
11 #ifndef SQUID_IPC_COORDINATOR_H
12 #define SQUID_IPC_COORDINATOR_H
13
14 #include "ipc/Messages.h"
15 #include "ipc/Port.h"
16 #include "ipc/SharedListen.h"
17 #include "ipc/StrandCoords.h"
18 #include "ipc/StrandSearch.h"
19 #include "mgr/forward.h"
20 #if SQUID_SNMP
21 #include "snmp/forward.h"
22 #endif
23 #include <list>
24 #include <map>
25
26 namespace Ipc
27 {
28
29 /// Coordinates shared activities of Strands (Squid processes or threads)
30 class Coordinator: public Port
31 {
32 CBDATA_CLASS(Coordinator);
33
34 public:
35 static Coordinator* Instance();
36
37 public:
38 Coordinator();
39
40 void broadcastSignal(int sig) const; ///< send sig to registered strands
41
42 const StrandCoords &strands() const; ///< currently registered strands
43
44 protected:
45 virtual void start(); // Port (AsyncJob) API
46 virtual void receive(const TypedMsgHdr& message); // Port API
47
48 StrandCoord* findStrand(int kidId); ///< registered strand or NULL
49 void registerStrand(const StrandCoord &); ///< adds or updates existing
50 void handleRegistrationRequest(const HereIamMessage &); ///< register,ACK
51
52 /// answer the waiting search request
53 void notifySearcher(const StrandSearchRequest &request, const StrandCoord&);
54 /// answers or queues the request if the answer is not yet known
55 void handleSearchRequest(const StrandSearchRequest &request);
56
57 /// returns cached socket or calls openListenSocket()
58 void handleSharedListenRequest(const SharedListenRequest& request);
59 void handleCacheMgrRequest(const Mgr::Request& request);
60 void handleCacheMgrResponse(const Mgr::Response& response);
61 #if SQUID_SNMP
62 void handleSnmpRequest(const Snmp::Request& request);
63 void handleSnmpResponse(const Snmp::Response& response);
64 #endif
65 /// calls comm_open_listener()
66 Comm::ConnectionPointer openListenSocket(const SharedListenRequest& request, int &errNo);
67
68 private:
69 StrandCoords strands_; ///< registered processes and threads
70
71 typedef std::list<StrandSearchRequest> Searchers; ///< search requests
72 Searchers searchers; ///< yet unanswered search requests in arrival order
73
74 typedef std::map<OpenListenerParams, Comm::ConnectionPointer> Listeners; ///< params:connection map
75 Listeners listeners; ///< cached comm_open_listener() results
76
77 static Coordinator* TheInstance; ///< the only class instance in existence
78
79 private:
80 Coordinator(const Coordinator&); // not implemented
81 Coordinator& operator =(const Coordinator&); // not implemented
82 };
83
84 } // namespace Ipc
85
86 #endif /* SQUID_IPC_COORDINATOR_H */
87