]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Strand.cc
Merged from parent (trunk r10600).
[thirdparty/squid.git] / src / ipc / Strand.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "config.h"
9 #include "base/TextException.h"
10 #include "ipc/Strand.h"
11 #include "ipc/Messages.h"
12 #include "ipc/SharedListen.h"
13 #include "ipc/Kids.h"
14
15
16 CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand);
17
18
19 Ipc::Strand::Strand():
20 Port(MakeAddr(strandAddrPfx, KidIdentifier)),
21 isRegistered(false)
22 {
23 }
24
25 void Ipc::Strand::start()
26 {
27 Port::start();
28 registerSelf();
29 }
30
31 void Ipc::Strand::registerSelf()
32 {
33 debugs(54, 6, HERE);
34 Must(!isRegistered);
35 TypedMsgHdr message;
36 StrandCoord(KidIdentifier, getpid()).pack(message);
37 SendMessage(coordinatorAddr, message);
38 setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
39 }
40
41 void Ipc::Strand::receive(const TypedMsgHdr &message)
42 {
43 debugs(54, 6, HERE << message.type());
44 switch (message.type()) {
45
46 case mtRegistration:
47 handleRegistrationResponse(StrandCoord(message));
48 break;
49
50 case mtSharedListenResponse:
51 SharedListenJoined(SharedListenResponse(message));
52 break;
53
54 default:
55 debugs(54, 1, HERE << "Unhandled message type: " << message.type());
56 break;
57 }
58 }
59
60 void Ipc::Strand::handleRegistrationResponse(const StrandCoord &strand)
61 {
62 // handle registration response from the coordinator; it could be stale
63 if (strand.kidId == KidIdentifier && strand.pid == getpid()) {
64 debugs(54, 6, "kid" << KidIdentifier << " registered");
65 clearTimeout(); // we are done
66 } else {
67 // could be an ACK to the registration message of our dead predecessor
68 debugs(54, 6, "kid" << KidIdentifier << " is not yet registered");
69 // keep listening, with a timeout
70 }
71 }
72
73 void Ipc::Strand::timedout()
74 {
75 debugs(54, 6, HERE << isRegistered);
76 if (!isRegistered)
77 fatalf("kid%d registration timed out", KidIdentifier);
78 }