2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 54 Interprocess Communication */
11 #ifndef SQUID_IPC_FORWARDER_H
12 #define SQUID_IPC_FORWARDER_H
14 #include "base/AsyncJob.h"
16 #include "ipc/Request.h"
17 #include "mgr/ActionParams.h"
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.
28 class Forwarder
: public AsyncJob
30 CBDATA_CLASS(Forwarder
);
33 Forwarder(Request::Pointer aRequest
, double aTimeout
);
36 /// finds and calls the right Forwarder upon Coordinator's response
37 static void HandleRemoteAck(unsigned int requestId
);
39 /* has-to-be-public AsyncJob API */
40 virtual void callException(const std::exception
& e
);
45 virtual void swanSong();
46 virtual bool doneAll() const;
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();
55 static void RequestTimedOut(void* param
);
56 void requestTimedOut();
57 void removeTimeoutEvent();
58 static AsyncCall::Pointer
DequeueRequest(unsigned int requestId
);
61 Request::Pointer request
;
62 const double timeout
; ///< response wait timeout in seconds
64 /// maps request->id to Forwarder::handleRemoteAck callback
65 typedef std::map
<unsigned int, AsyncCall::Pointer
> RequestsMap
;
66 static RequestsMap TheRequestsMap
; ///< pending Coordinator requests
68 static unsigned int LastRequestId
; ///< last requestId used
73 #endif /* SQUID_IPC_FORWARDER_H */