]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Forwarder.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ipc / Forwarder.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_FORWARDER_H
12 #define SQUID_IPC_FORWARDER_H
13
14 #include "base/AsyncJob.h"
15 #include "cbdata.h"
16 #include "ipc/Request.h"
17 #include "mgr/ActionParams.h"
18
19 #include <map>
20
21 namespace Ipc
22 {
23
24 /** Forwards a worker request to coordinator.
25 * Waits for an ACK from Coordinator
26 * Send the data unit with an error response if forwarding fails.
27 */
28 class Forwarder: public AsyncJob
29 {
30 CBDATA_CLASS(Forwarder);
31
32 public:
33 Forwarder(Request::Pointer aRequest, double aTimeout);
34 virtual ~Forwarder();
35
36 /// finds and calls the right Forwarder upon Coordinator's response
37 static void HandleRemoteAck(unsigned int requestId);
38
39 /* has-to-be-public AsyncJob API */
40 virtual void callException(const std::exception& e);
41
42 protected:
43 /* AsyncJob API */
44 virtual void start();
45 virtual void swanSong();
46 virtual bool doneAll() const;
47
48 virtual void handleError();
49 virtual void handleTimeout();
50 virtual void handleException(const std::exception& e);
51
52 private:
53 static void RequestTimedOut(void* param);
54 void requestTimedOut();
55 void removeTimeoutEvent();
56
57 void handleRemoteAck();
58
59 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
60
61 protected:
62 Request::Pointer request;
63 const double timeout; ///< response wait timeout in seconds
64
65 /// maps request->id to Forwarder::handleRemoteAck callback
66 typedef std::map<unsigned int, AsyncCall::Pointer> RequestsMap;
67 static RequestsMap TheRequestsMap; ///< pending Coordinator requests
68
69 static unsigned int LastRequestId; ///< last requestId used
70 };
71
72 } // namespace Ipc
73
74 #endif /* SQUID_IPC_FORWARDER_H */
75