Squid Web Cache master
Loading...
Searching...
No Matches
Strand.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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{
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
62{
63 switch (message.rawType()) {
64
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
119void
121{
123 debugs(54, 6, "kid" << KidIdentifier << " registered");
124 clearTimeout(); // we are done
125}
126
128{
129 Mgr::Action::Pointer action =
131 action->respond(request);
132}
133
138
139#if SQUID_SNMP
141{
142 debugs(54, 6, MYNAME);
143 Snmp::SendResponse(request.requestId, request.pdu);
144}
145
151#endif
152
154{
155 debugs(54, 6, isRegistered);
156 if (!isRegistered)
157 fatalf("kid%d registration timed out", KidIdentifier);
158}
159
#define Assure(condition)
Definition Assure.h:35
#define Must(condition)
#define CBDATA_NAMESPACED_CLASS_INIT(namespace, type)
Definition cbdata.h:333
Mgr::Action::Pointer createRequestedAction(const Mgr::ActionParams &)
static CacheManager * GetInstance()
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
static void HandleOpenResponse(const Ipc::StrandMessage &)
handle open response from coordinator
Definition IpcIoFile.cc:456
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition IpcIoFile.cc:524
static void HandleRemoteAck(RequestId)
finds and calls the right Forwarder upon Coordinator's response
Definition Forwarder.cc:174
Waits for and receives incoming IPC messages; kids handle the messages.
Definition Port.h:22
void start() override=0
called by AsyncStart; do not call directly
Definition Port.cc:32
virtual void receive(const TypedMsgHdr &)=0
Definition Port.cc:76
RequestId requestId
matches the request[or] with the response
Definition Request.h:38
RequestId requestId
the ID of the request we are responding to
Definition Response.h:36
a response to SharedListenRequest
int kidId
internal Squid process number
Definition StrandCoord.h:31
an IPC message carrying StrandCoord
Definition StrandCoord.h:39
static void NotifyCoordinator(MessageType, const char *tag)
creates and sends StrandMessage to Coordinator
StrandCoord strand
messageType-specific coordinates (e.g., sender)
Definition StrandCoord.h:52
void handleCacheMgrRequest(const Mgr::Request &request)
Definition Strand.cc:127
void handleRegistrationResponse(const StrandMessage &)
let Coordinator know this strand exists
Definition Strand.cc:120
void receive(const TypedMsgHdr &message) override
Definition Strand.cc:61
void handleSnmpResponse(const Snmp::Response &response)
Definition Strand.cc:146
void handleCacheMgrResponse(const Mgr::Response &response)
Definition Strand.cc:134
void timedout() override
called after setTimeout() if timed out
Definition Strand.cc:153
void start() override
called by AsyncStart; do not call directly
Definition Strand.cc:46
void handleSnmpRequest(const Snmp::Request &request)
Definition Strand.cc:140
void registerSelf()
Definition Strand.cc:52
struct msghdr with a known type, fixed-size I/O and control buffers
Definition TypedMsgHdr.h:35
int rawType() const
Definition TypedMsgHdr.h:51
cache manager request
Definition Request.h:24
ActionParams params
action name and parameters
Definition Request.h:37
SNMP request.
Definition Request.h:25
Pdu pdu
SNMP protocol data unit.
Definition Request.h:36
#define MYNAME
Definition Stream.h:219
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
void fatalf(const char *fmt,...)
Definition fatal.cc:68
int KidIdentifier
void SharedListenJoined(const SharedListenResponse &response)
process Coordinator response to SharedListenRequest
const char strandAddrLabel[]
strand's listening address unique label
Definition Port.cc:24
const Answer & Mine(const Answer &answer)
@ mtCacheMgrRequest
Definition Messages.h:35
@ mtRegisterStrand
notifies about our strand existence
Definition Messages.h:22
@ mtIpcIoNotification
Definition Messages.h:31
@ mtCollapsedForwardingNotification
Definition Messages.h:33
@ mtStrandReady
an mtFindStrand answer: the strand exists and should be usable
Definition Messages.h:26
@ mtSnmpResponse
Definition Messages.h:40
@ mtSnmpRequest
Definition Messages.h:39
@ mtStrandRegistered
acknowledges mtRegisterStrand acceptance
Definition Messages.h:23
@ mtCacheMgrResponse
Definition Messages.h:36
@ mtSharedListenResponse
Definition Messages.h:29
void SendResponse(Ipc::RequestId, const Pdu &)
Definition Forwarder.cc:97