]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Forwarder.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ipc / Forwarder.h
CommitLineData
51ea0904 1/*
77b1029d 2 * Copyright (C) 1996-2020 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
51ea0904
CT
48 virtual void handleError();
49 virtual void handleTimeout();
50 virtual void handleException(const std::exception& e);
51ea0904
CT
51
52private:
53 static void RequestTimedOut(void* param);
54 void requestTimedOut();
55 void removeTimeoutEvent();
7a5451fe 56
9e930115
AR
57 void handleRemoteAck();
58
51ea0904
CT
59 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
60
61protected:
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
51ea0904
CT
70};
71
72} // namespace Ipc
73
74#endif /* SQUID_IPC_FORWARDER_H */
f53969cc 75