]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Forwarder.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Forwarder.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_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 cleanup(); ///< perform cleanup actions
49 virtual void handleError();
50 virtual void handleTimeout();
51 virtual void handleException(const std::exception& e);
52 virtual void handleRemoteAck();
53
54 private:
55 static void RequestTimedOut(void* param);
56 void requestTimedOut();
57 void removeTimeoutEvent();
58 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
59
60 protected:
61 Request::Pointer request;
62 const double timeout; ///< response wait timeout in seconds
63
64 /// maps request->id to Forwarder::handleRemoteAck callback
65 typedef std::map<unsigned int, AsyncCall::Pointer> RequestsMap;
66 static RequestsMap TheRequestsMap; ///< pending Coordinator requests
67
68 static unsigned int LastRequestId; ///< last requestId used
69 };
70
71 } // namespace Ipc
72
73 #endif /* SQUID_IPC_FORWARDER_H */
74