]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Strand.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/TextException.h"
10 #include "ipc/Strand.h"
11 #include "ipc/StrandCoord.h"
12 #include "ipc/Messages.h"
13 #include "ipc/SharedListen.h"
15 #include "mgr/Request.h"
16 #include "mgr/Response.h"
17 #include "mgr/Forwarder.h"
18 #include "CacheManager.h"
21 CBDATA_NAMESPACED_CLASS_INIT(Ipc
, Strand
);
24 Ipc::Strand::Strand():
25 Port(MakeAddr(strandAddrPfx
, KidIdentifier
)),
30 void Ipc::Strand::start()
36 void Ipc::Strand::registerSelf()
41 StrandCoord(KidIdentifier
, getpid()).pack(message
);
42 SendMessage(coordinatorAddr
, message
);
43 setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
46 void Ipc::Strand::receive(const TypedMsgHdr
&message
)
48 debugs(54, 6, HERE
<< message
.type());
49 switch (message
.type()) {
52 handleRegistrationResponse(StrandCoord(message
));
55 case mtSharedListenResponse
:
56 SharedListenJoined(SharedListenResponse(message
));
59 case mtCacheMgrRequest
:
60 handleCacheMgrRequest(Mgr::Request(message
));
63 case mtCacheMgrResponse
:
64 handleCacheMgrResponse(Mgr::Response(message
));
68 debugs(54, 1, HERE
<< "Unhandled message type: " << message
.type());
73 void Ipc::Strand::handleRegistrationResponse(const StrandCoord
&strand
)
75 // handle registration response from the coordinator; it could be stale
76 if (strand
.kidId
== KidIdentifier
&& strand
.pid
== getpid()) {
77 debugs(54, 6, "kid" << KidIdentifier
<< " registered");
78 clearTimeout(); // we are done
80 // could be an ACK to the registration message of our dead predecessor
81 debugs(54, 6, "kid" << KidIdentifier
<< " is not yet registered");
82 // keep listening, with a timeout
86 void Ipc::Strand::handleCacheMgrRequest(const Mgr::Request
& request
)
88 Mgr::Action::Pointer action
=
89 CacheManager::GetInstance()->createRequestedAction(request
.params
);
90 action
->respond(request
);
93 void Ipc::Strand::handleCacheMgrResponse(const Mgr::Response
& response
)
95 Mgr::Forwarder::HandleRemoteAck(response
.requestId
);
98 void Ipc::Strand::timedout()
100 debugs(54, 6, HERE
<< isRegistered
);
102 fatalf("kid%d registration timed out", KidIdentifier
);