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{
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{
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{
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
CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand)
#define Must(condition)
Definition: TextException.h:75
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:31
virtual void receive(const TypedMsgHdr &)=0
Definition: Port.cc:78
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
Definition: SharedListen.h:63
pid_t pid
OS process or thread identifier.
Definition: StrandCoord.h:32
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
Definition: StrandCoord.cc:62
StrandCoord strand
messageType-specific coordinates (e.g., sender)
Definition: StrandCoord.h:52
void handleCacheMgrRequest(const Mgr::Request &request)
Definition: Strand.cc:133
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:152
void handleCacheMgrResponse(const Mgr::Response &response)
Definition: Strand.cc:140
void timedout() override
called after setTimeout() if timed out
Definition: Strand.cc:159
void start() override
called by AsyncStart; do not call directly
Definition: Strand.cc:46
void handleSnmpRequest(const Snmp::Request &request)
Definition: Strand.cc:146
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:236
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
int KidIdentifier
Definition: IpcIoFile.h:24
void SharedListenJoined(const SharedListenResponse &response)
process Coordinator response to SharedListenRequest
const char strandAddrLabel[]
strand's listening address unique label
Definition: Port.cc:23
const Answer & Mine(const Answer &answer)
Definition: QuestionerId.h:56
@ 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:95
static bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:315

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors