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