]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Inquirer.h
Protect SMP kids from unsolicited IPC answers (#771)
[thirdparty/squid.git] / src / ipc / Inquirer.h
1 /*
2 * Copyright (C) 1996-2020 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_INQUIRER_H
12 #define SQUID_IPC_INQUIRER_H
13
14 #include "base/AsyncJob.h"
15 #include "base/AsyncJobCalls.h"
16 #include "base/forward.h"
17 #include "ipc/forward.h"
18 #include "ipc/Request.h"
19 #include "ipc/Response.h"
20 #include "ipc/StrandCoords.h"
21 #include <map>
22
23 namespace Ipc
24 {
25
26 /// Coordinator's job that sends a cache manage request to each strand,
27 /// aggregating individual strand responses and dumping the result if needed
28 class Inquirer: public AsyncJob
29 {
30 CBDATA_CLASS(Inquirer);
31
32 public:
33 Inquirer(Request::Pointer aRequest, const Ipc::StrandCoords& coords, double aTimeout);
34 virtual ~Inquirer();
35
36 /// finds and calls the right Inquirer upon strand's response
37 static void HandleRemoteAck(const Response& response);
38
39 /* has-to-be-public AsyncJob API */
40 virtual void callException(const std::exception& e);
41
42 CodeContextPointer codeContext;
43
44 protected:
45 /* AsyncJob API */
46 virtual void start();
47 virtual void swanSong();
48 virtual bool doneAll() const;
49 virtual const char *status() const;
50
51 /// inquire the next strand
52 virtual void inquire();
53 /// perform cleanup actions on completion of job
54 virtual void cleanup();
55 /// do specific exception handling
56 virtual void handleException(const std::exception& e);
57 /// send response to client
58 virtual void sendResponse() = 0;
59 /// perform aggregating of responses and returns true if need to continue
60 virtual bool aggregate(Response::Pointer aResponse) = 0;
61
62 private:
63 typedef UnaryMemFunT<Inquirer, Response::Pointer, Response::Pointer> HandleAckDialer;
64
65 void handleRemoteAck(Response::Pointer response);
66
67 static AsyncCall::Pointer DequeueRequest(RequestId::Index);
68
69 static void RequestTimedOut(void* param);
70 void requestTimedOut();
71 void removeTimeoutEvent();
72
73 protected:
74 Request::Pointer request; ///< cache manager request received from client
75
76 Ipc::StrandCoords strands; ///< all strands we want to query, in order
77 Ipc::StrandCoords::const_iterator pos; ///< strand we should query now
78
79 const double timeout; ///< number of seconds to wait for strand response
80
81 /// maps request->id to Inquirer::handleRemoteAck callback
82 typedef std::map<RequestId::Index, AsyncCall::Pointer> RequestsMap;
83 static RequestsMap TheRequestsMap; ///< pending strand requests
84
85 static RequestId::Index LastRequestId; ///< last requestId used
86 };
87
88 } // namespace Ipc
89
90 #endif /* SQUID_IPC_INQUIRER_H */
91