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