Strand.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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/SharedListen.h"
22 #include "ipc/Strand.h"
23 #include "ipc/StrandCoord.h"
24 #include "ipc/StrandSearch.h"
25 #include "mgr/Forwarder.h"
26 #include "mgr/Request.h"
27 #include "mgr/Response.h"
28 #if HAVE_DISKIO_MODULE_IPCIO
29 #include "DiskIO/IpcIo/IpcIoFile.h" /* XXX: scope boundary violation */
30 #endif
31 #if SQUID_SNMP
32 #include "snmp/Forwarder.h"
33 #include "snmp/Request.h"
34 #include "snmp/Response.h"
35 #endif
36 
37 CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand);
38 
41  isRegistered(false)
42 {
43 }
44 
46 {
47  Port::start();
48  registerSelf();
49 }
50 
52 {
53  debugs(54, 6, HERE);
54  Must(!isRegistered);
55 
57  TypedMsgHdr message;
58  ann.pack(message);
60  setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable?
61 }
62 
63 void Ipc::Strand::receive(const TypedMsgHdr &message)
64 {
65  debugs(54, 6, HERE << message.type());
66  switch (message.type()) {
67 
68  case mtRegistration:
69  handleRegistrationResponse(HereIamMessage(message));
70  break;
71 
74  break;
75 
76 #if HAVE_DISKIO_MODULE_IPCIO
79  break;
80 
83  break;
84 #endif /* HAVE_DISKIO_MODULE_IPCIO */
85 
86  case mtCacheMgrRequest: {
87  const Mgr::Request req(message);
88  handleCacheMgrRequest(req);
89  }
90  break;
91 
92  case mtCacheMgrResponse: {
93  const Mgr::Response resp(message);
94  handleCacheMgrResponse(resp);
95  }
96  break;
97 
100  break;
101 
102 #if SQUID_SNMP
103  case mtSnmpRequest: {
104  const Snmp::Request req(message);
105  handleSnmpRequest(req);
106  }
107  break;
108 
109  case mtSnmpResponse: {
110  const Snmp::Response resp(message);
111  handleSnmpResponse(resp);
112  }
113  break;
114 #endif
115 
116  default:
117  debugs(54, DBG_IMPORTANT, HERE << "Unhandled message type: " << message.type());
118  break;
119  }
120 }
121 
123 {
124  // handle registration response from the coordinator; it could be stale
125  if (msg.strand.kidId == KidIdentifier && msg.strand.pid == getpid()) {
126  debugs(54, 6, "kid" << KidIdentifier << " registered");
127  clearTimeout(); // we are done
128  } else {
129  // could be an ACK to the registration message of our dead predecessor
130  debugs(54, 6, "kid" << KidIdentifier << " is not yet registered");
131  // keep listening, with a timeout
132  }
133 }
134 
136 {
139  action->respond(request);
140 }
141 
143 {
145 }
146 
147 #if SQUID_SNMP
149 {
150  debugs(54, 6, HERE);
151  Snmp::SendResponse(request.requestId, request.pdu);
152 }
153 
155 {
156  debugs(54, 6, HERE);
158 }
159 #endif
160 
162 {
163  debugs(54, 6, HERE << isRegistered);
164  if (!isRegistered)
165  fatalf("kid%d registration timed out", KidIdentifier);
166 }
167 
virtual void start()=0
called by AsyncStart; do not call directly
Definition: Port.cc:30
strand registration with Coordinator (also used as an ACK)
Definition: StrandCoord.h:36
cache manager request
Definition: Request.h:22
void handleSnmpResponse(const Snmp::Response &response)
Definition: Strand.cc:154
static void HandleOpenResponse(const Ipc::StrandSearchResponse &response)
handle open response from coordinator
Definition: IpcIoFile.cc:421
StrandCoord strand
registrant coordinates and related details
Definition: StrandCoord.h:44
Strand location details.
Definition: StrandCoord.h:19
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
unsigned int requestId
ID of request we are responding to.
Definition: Response.h:38
int kidId
internal Squid process number
Definition: StrandCoord.h:29
void SharedListenJoined(const SharedListenResponse &response)
process Coordinator response to SharedListenRequest
void handleCacheMgrResponse(const Mgr::Response &response)
Definition: Strand.cc:142
Pdu pdu
SNMP protocol data unit.
Definition: Request.h:39
static CacheManager * GetInstance()
void fatalf(const char *fmt,...)
Definition: fatal.cc:79
void pack(TypedMsgHdr &hdrMsg) const
prepare for sendmsg()
Definition: StrandCoord.cc:51
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
a response to SharedListenRequest
Definition: SharedListen.h:63
ActionParams params
action name and parameters
Definition: Request.h:39
void SendResponse(unsigned int requestId, const Pdu &pdu)
Definition: Forwarder.cc:90
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define DBG_IMPORTANT
Definition: Debug.h:45
void handleSnmpRequest(const Snmp::Request &request)
Definition: Strand.cc:148
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition: IpcIoFile.cc:483
unsigned int requestId
unique for sender; matches request w/ response
Definition: Request.h:39
void registerSelf()
Definition: Strand.cc:51
Mgr::Action::Pointer createRequestedAction(const Mgr::ActionParams &)
SNMP request.
Definition: Request.h:24
static void HandleRemoteAck(unsigned int requestId)
finds and calls the right Forwarder upon Coordinator's response
Definition: Forwarder.cc:177
void SendMessage(const String &toAddress, const TypedMsgHdr &message)
Definition: UdsOp.cc:188
asynchronous strand search response
Definition: StrandSearch.h:33
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
virtual void receive(const TypedMsgHdr &message)
handle IPC message just read
Definition: Strand.cc:63
bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:311
#define Must(cond)
Definition: TextException.h:89
const char strandAddrLabel[]
strand's listening address unique label
Definition: Port.cc:22
Waits for and receives incoming IPC messages; kids handle the messages.
Definition: Port.h:21
int KidIdentifier
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:31
int type() const
returns stored type or zero if none
Definition: TypedMsgHdr.cc:68
virtual void timedout()
called after setTimeout() if timed out
Definition: Strand.cc:161
void handleCacheMgrRequest(const Mgr::Request &request)
Definition: Strand.cc:135
void handleRegistrationResponse(const HereIamMessage &msg)
let Coordinator know this strand exists
Definition: Strand.cc:122
static String CoordinatorAddr()
get the IPC message address for coordinator process
Definition: Port.cc:64
virtual void start()
called by AsyncStart; do not call directly
Definition: Strand.cc:45
pid_t pid
OS process or thread identifier.
Definition: StrandCoord.h:30
#define false
Definition: GnuRegex.c:233
CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors