]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Strand.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/Subscription.h"
10 #include "base/TextException.h"
11 #include "comm/Connection.h"
12 #include "ipc/Strand.h"
13 #include "ipc/StrandCoord.h"
14 #include "ipc/Messages.h"
15 #include "ipc/SharedListen.h"
17 #include "mgr/Request.h"
18 #include "mgr/Response.h"
19 #include "mgr/Forwarder.h"
20 #include "CacheManager.h"
22 CBDATA_NAMESPACED_CLASS_INIT(Ipc
, Strand
);
25 Ipc::Strand::Strand():
26 Port(MakeAddr(strandAddrPfx
, KidIdentifier
)),
31 void Ipc::Strand::start()
37 void Ipc::Strand::registerSelf()
42 StrandCoord(KidIdentifier
, getpid()).pack(message
);
43 SendMessage(coordinatorAddr
, message
);
44 setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
47 void Ipc::Strand::receive(const TypedMsgHdr
&message
)
49 debugs(54, 6, HERE
<< message
.type());
50 switch (message
.type()) {
53 handleRegistrationResponse(StrandCoord(message
));
56 case mtSharedListenResponse
:
57 SharedListenJoined(SharedListenResponse(message
));
60 case mtCacheMgrRequest
:
61 handleCacheMgrRequest(Mgr::Request(message
));
64 case mtCacheMgrResponse
:
65 handleCacheMgrResponse(Mgr::Response(message
));
69 debugs(54, 1, HERE
<< "Unhandled message type: " << message
.type());
74 void Ipc::Strand::handleRegistrationResponse(const StrandCoord
&strand
)
76 // handle registration response from the coordinator; it could be stale
77 if (strand
.kidId
== KidIdentifier
&& strand
.pid
== getpid()) {
78 debugs(54, 6, "kid" << KidIdentifier
<< " registered");
79 clearTimeout(); // we are done
81 // could be an ACK to the registration message of our dead predecessor
82 debugs(54, 6, "kid" << KidIdentifier
<< " is not yet registered");
83 // keep listening, with a timeout
87 void Ipc::Strand::handleCacheMgrRequest(const Mgr::Request
& request
)
89 Mgr::Action::Pointer action
=
90 CacheManager::GetInstance()->createRequestedAction(request
.params
);
91 action
->respond(request
);
94 void Ipc::Strand::handleCacheMgrResponse(const Mgr::Response
& response
)
96 Mgr::Forwarder::HandleRemoteAck(response
.requestId
);
99 void Ipc::Strand::timedout()
101 debugs(54, 6, HERE
<< isRegistered
);
103 fatalf("kid%d registration timed out", KidIdentifier
);