]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Strand.cc
Switched from sendto/recvfrom to sendmsg/recvmsg for UDS I/O. Replaced
[thirdparty/squid.git] / src / ipc / Strand.cc
CommitLineData
10cefb7b 1/*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
10cefb7b 8#include "config.h"
9#include "ipc/Strand.h"
1bac0258 10#include "ipc/Messages.h"
10cefb7b 11#include "ipc/Kids.h"
12
13
14CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand);
15
16
17Ipc::Strand::Strand():
ba568924 18 Port(MakeAddr(strandAddrPfx, KidIdentifier)),
10cefb7b 19 isRegistered(false)
20{
21}
22
23void Ipc::Strand::start()
24{
ba568924
AR
25 Port::start();
26 registerSelf();
10cefb7b 27}
28
ba568924 29void Ipc::Strand::registerSelf()
10cefb7b 30{
31 debugs(54, 6, HERE);
ba568924 32 Must(!isRegistered);
1bac0258
AR
33 TypedMsgHdr message;
34 StrandCoord(KidIdentifier, getpid()).pack(message);
35 SendMessage(coordinatorAddr, message);
ba568924 36 setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
10cefb7b 37}
38
1bac0258 39void Ipc::Strand::receive(const TypedMsgHdr &message)
10cefb7b 40{
41 debugs(54, 6, HERE);
42 switch (message.type()) {
43
ba568924 44 case mtRegistration:
1bac0258 45 handleRegistrationResponse(StrandCoord(message));
10cefb7b 46 break;
47
48 default:
ba568924 49 debugs(54, 6, HERE << "Unhandled message type: " << message.type());
10cefb7b 50 break;
51 }
52}
53
1bac0258 54void Ipc::Strand::handleRegistrationResponse(const StrandCoord &strand)
10cefb7b 55{
ba568924
AR
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
10cefb7b 64 }
65}
66
ba568924 67void Ipc::Strand::timedout()
10cefb7b 68{
ba568924
AR
69 debugs(54, 6, HERE << isRegistered);
70 if (!isRegistered)
71 fatalf("kid%d registration timed out", KidIdentifier);
10cefb7b 72}