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