]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Forwarder.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Forwarder.h
CommitLineData
51ea0904 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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"
c6983ec7 15#include "cbdata.h"
51ea0904 16#include "ipc/Request.h"
c6983ec7
FC
17#include "mgr/ActionParams.h"
18
51ea0904
CT
19#include <map>
20
51ea0904
CT
21namespace 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 */
28class Forwarder: public AsyncJob
29{
5c2f68b7
AJ
30 CBDATA_CLASS(Forwarder);
31
51ea0904
CT
32public:
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
42protected:
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
54private:
55 static void RequestTimedOut(void* param);
56 void requestTimedOut();
57 void removeTimeoutEvent();
58 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
59
60protected:
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
51ea0904
CT
69};
70
71} // namespace Ipc
72
73#endif /* SQUID_IPC_FORWARDER_H */
f53969cc 74