]>
Commit | Line | Data |
---|---|---|
51ea0904 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
51ea0904 | 3 | * |
bbc27441 AJ |
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. | |
51ea0904 CT |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
51ea0904 CT |
11 | #ifndef SQUID_IPC_FORWARDER_H |
12 | #define SQUID_IPC_FORWARDER_H | |
13 | ||
14 | #include "base/AsyncJob.h" | |
87388f15 | 15 | #include "base/forward.h" |
c6983ec7 | 16 | #include "cbdata.h" |
51ea0904 | 17 | #include "ipc/Request.h" |
c6983ec7 FC |
18 | #include "mgr/ActionParams.h" |
19 | ||
51ea0904 CT |
20 | #include <map> |
21 | ||
51ea0904 CT |
22 | namespace Ipc |
23 | { | |
24 | ||
25 | /** Forwards a worker request to coordinator. | |
26 | * Waits for an ACK from Coordinator | |
27 | * Send the data unit with an error response if forwarding fails. | |
28 | */ | |
29 | class Forwarder: public AsyncJob | |
30 | { | |
337b9aa4 | 31 | CBDATA_INTERMEDIATE(); |
5c2f68b7 | 32 | |
51ea0904 CT |
33 | public: |
34 | Forwarder(Request::Pointer aRequest, double aTimeout); | |
337b9aa4 | 35 | ~Forwarder() override; |
51ea0904 CT |
36 | |
37 | /// finds and calls the right Forwarder upon Coordinator's response | |
4c218615 | 38 | static void HandleRemoteAck(RequestId); |
51ea0904 CT |
39 | |
40 | /* has-to-be-public AsyncJob API */ | |
337b9aa4 | 41 | void callException(const std::exception& e) override; |
51ea0904 | 42 | |
87388f15 EB |
43 | CodeContextPointer codeContext; |
44 | ||
51ea0904 CT |
45 | protected: |
46 | /* AsyncJob API */ | |
337b9aa4 AR |
47 | void start() override; |
48 | void swanSong() override; | |
49 | bool doneAll() const override; | |
51ea0904 | 50 | |
51ea0904 CT |
51 | virtual void handleError(); |
52 | virtual void handleTimeout(); | |
53 | virtual void handleException(const std::exception& e); | |
51ea0904 CT |
54 | |
55 | private: | |
56 | static void RequestTimedOut(void* param); | |
57 | void requestTimedOut(); | |
58 | void removeTimeoutEvent(); | |
7a5451fe | 59 | |
9e930115 AR |
60 | void handleRemoteAck(); |
61 | ||
4c218615 | 62 | static AsyncCall::Pointer DequeueRequest(RequestId::Index); |
51ea0904 CT |
63 | |
64 | protected: | |
65 | Request::Pointer request; | |
66 | const double timeout; ///< response wait timeout in seconds | |
67 | ||
68 | /// maps request->id to Forwarder::handleRemoteAck callback | |
4c218615 | 69 | typedef std::map<RequestId::Index, AsyncCall::Pointer> RequestsMap; |
51ea0904 CT |
70 | static RequestsMap TheRequestsMap; ///< pending Coordinator requests |
71 | ||
4c218615 | 72 | static RequestId::Index LastRequestId; ///< last requestId used |
51ea0904 CT |
73 | }; |
74 | ||
75 | } // namespace Ipc | |
76 | ||
77 | #endif /* SQUID_IPC_FORWARDER_H */ | |
f53969cc | 78 |