Strand.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 54 Interprocess Communication */
10 
11 #include "squid.h"
12 #include "base/Subscription.h"
13 #include "base/TextException.h"
14 #include "CacheManager.h"
15 #include "CollapsedForwarding.h"
16 #include "comm/Connection.h"
17 #include "fatal.h"
18 #include "globals.h"
19 #include "ipc/Kids.h"
20 #include "ipc/Messages.h"
21 #include "ipc/QuestionerId.h"
22 #include "ipc/SharedListen.h"
23 #include "ipc/Strand.h"
24 #include "ipc/StrandCoord.h"
25 #include "ipc/StrandSearch.h"
26 #include "mgr/Forwarder.h"
27 #include "mgr/Request.h"
28 #include "mgr/Response.h"
29 #if HAVE_DISKIO_MODULE_IPCIO
30 #include "DiskIO/IpcIo/IpcIoFile.h" /* XXX: scope boundary violation */
31 #endif
32 #if SQUID_SNMP
33 #include "snmp/Forwarder.h"
34 #include "snmp/Request.h"
35 #include "snmp/Response.h"
36 #endif
37 
39 
42  isRegistered(false)
43 {
44 }
45 
47 {
48  Port::start();
49  registerSelf();
50 }
51 
53 {
54  debugs(54, 6, MYNAME);
55  Must(!isRegistered);
56 
58  setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
59 }
60 
61 void Ipc::Strand::receive(const TypedMsgHdr &message)
62 {
63  switch (message.rawType()) {
64 
65  case mtStrandRegistered:
66  handleRegistrationResponse(Mine(StrandMessage(message)));
67  break;
68 
71  break;
72 
73 #if HAVE_DISKIO_MODULE_IPCIO
74  case mtStrandReady:
76  break;
77 
80  break;
81 #endif /* HAVE_DISKIO_MODULE_IPCIO */
82 
83  case mtCacheMgrRequest: {
84  const Mgr::Request req(message);
85  handleCacheMgrRequest(req);
86  }
87  break;
88 
89  case mtCacheMgrResponse: {
90  const Mgr::Response resp(message);
91  handleCacheMgrResponse(Mine(resp));
92  }
93  break;
94 
97  break;
98 
99 #if SQUID_SNMP
100  case mtSnmpRequest: {
101  const Snmp::Request req(message);
102  handleSnmpRequest(req);
103  }
104  break;
105 
106  case mtSnmpResponse: {
107  const Snmp::Response resp(message);
108  handleSnmpResponse(Mine(resp));
109  }
110  break;
111 #endif
112 
113  default:
114  Port::receive(message);
115  break;
116  }
117 }
118 
119 void
121 {
122  // handle registration response from the coordinator; it could be stale
123  if (msg.strand.kidId == KidIdentifier && msg.strand.pid == getpid()) {
124  debugs(54, 6, "kid" << KidIdentifier << " registered");
125  clearTimeout(); // we are done
126  } else {
127  // could be an ACK to the registration message of our dead predecessor
128  debugs(54, 6, "kid" << KidIdentifier << " is not yet registered");
129  // keep listening, with a timeout
130  }
131 }
132 
134 {
135  Mgr::Action::Pointer action =
137  action->respond(request);
138 }
139 
141 {
143 }
144 
145 #if SQUID_SNMP
147 {
148  debugs(54, 6, MYNAME);
149  Snmp::SendResponse(request.requestId, request.pdu);
150 }
151 
153 {
154  debugs(54, 6, MYNAME);
156 }
157 #endif
158 
160 {
161  debugs(54, 6, isRegistered);
162  if (!isRegistered)
163  fatalf("kid%d registration timed out", KidIdentifier);
164 }
165 
static void HandleRemoteAck(RequestId)
finds and calls the right Forwarder upon Coordinator's response
Definition: Forwarder.cc:174
void handleSnmpResponse(const Snmp::Response &response)
Definition: Strand.cc:152
@ mtStrandReady
an mtFindStrand answer: the strand exists and should be usable
Definition: Messages.h:26
void receive(const TypedMsgHdr &message) override
Definition: Strand.cc:61
RequestId requestId
matches the request[or] with the response
Definition: Request.h:38
StrandCoord strand
messageType-specific coordinates (e.g., sender)
Definition: StrandCoord.h:52
int KidIdentifier
@ mtSharedListenResponse
Definition: Messages.h:29
int kidId
internal Squid process number
Definition: StrandCoord.h:31
@ mtIpcIoNotification
Definition: Messages.h:31
const char strandAddrLabel[]
strand's listening address unique label
Definition: Port.cc:23
@ mtCacheMgrResponse
Definition: Messages.h:36
static void NotifyCoordinator(MessageType, const char *tag)
creates and sends StrandMessage to Coordinator
Definition: StrandCoord.cc:62
@ mtStrandRegistered
acknowledges mtRegisterStrand acceptance
Definition: Messages.h:23
void handleRegistrationResponse(const StrandMessage &)
let Coordinator know this strand exists
Definition: Strand.cc:120
const Answer & Mine(const Answer &answer)
Definition: QuestionerId.h:56
static CacheManager * GetInstance()
@ mtSnmpRequest
Definition: Messages.h:39
int rawType() const
Definition: TypedMsgHdr.h:51
static void HandleOpenResponse(const Ipc::StrandMessage &)
handle open response from coordinator
Definition: IpcIoFile.cc:456
void registerSelf()
Definition: Strand.cc:52
void handleCacheMgrResponse(const Mgr::Response &response)
Definition: Strand.cc:140
@ mtCacheMgrRequest
Definition: Messages.h:35
void handleSnmpRequest(const Snmp::Request &request)
Definition: Strand.cc:146
SNMP request.
Definition: Request.h:24
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
@ mtSnmpResponse
Definition: Messages.h:40
void handleCacheMgrRequest(const Mgr::Request &request)
Definition: Strand.cc:133
cache manager request
Definition: Request.h:23
Waits for and receives incoming IPC messages; kids handle the messages.
Definition: Port.h:21
virtual void receive(const TypedMsgHdr &)=0
Definition: Port.cc:78
Mgr::Action::Pointer createRequestedAction(const Mgr::ActionParams &)
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
RequestId requestId
the ID of the request we are responding to
Definition: Response.h:36
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition: IpcIoFile.cc:524
void start() override
called by AsyncStart; do not call directly
Definition: Strand.cc:46
ActionParams params
action name and parameters
Definition: Request.h:37
an IPC message carrying StrandCoord
Definition: StrandCoord.h:38
@ mtRegisterStrand
notifies about our strand existence
Definition: Messages.h:22
@ mtCollapsedForwardingNotification
Definition: Messages.h:33
void start() override=0
called by AsyncStart; do not call directly
Definition: Port.cc:31
a response to SharedListenRequest
Definition: SharedListen.h:62
void SendResponse(Ipc::RequestId, const Pdu &)
Definition: Forwarder.cc:95
#define Must(condition)
Definition: TextException.h:75
Pdu pdu
SNMP protocol data unit.
Definition: Request.h:36
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:34
#define MYNAME
Definition: Stream.h:219
void SharedListenJoined(const SharedListenResponse &response)
process Coordinator response to SharedListenRequest
CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand)
pid_t pid
OS process or thread identifier.
Definition: StrandCoord.h:32
void timedout() override
Definition: Strand.cc:159
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
Definition: IpcIoFile.h:23

 

Introduction

Documentation

Support

Miscellaneous