clientStream.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 87 Client-side Stream routines. */
10
11#include "squid.h"
12#include "client_side_request.h"
13#include "clientStream.h"
14#include "http/Stream.h"
15#include "HttpReply.h"
16#include "HttpRequest.h"
17
85
86clientStreamNode::clientStreamNode(CSR * aReadfunc, CSCB * aCallback, CSD * aDetach, CSS * aStatus, ClientStreamData aData) :
87 head(nullptr),
88 readfunc(aReadfunc),
89 callback(aCallback),
90 detach(aDetach),
91 status(aStatus),
92 data(aData)
93{}
94
96{
97 debugs(87, 3, "Freeing clientStreamNode " << this);
98
100 data = nullptr;
101}
102
111void
112clientStreamInit(dlink_list * list, CSR * func, CSD * rdetach, CSS * readstatus,
113 ClientStreamData readdata, CSCB * callback, CSD * cdetach, ClientStreamData callbackdata,
114 StoreIOBuffer tailBuffer)
115{
116 clientStreamNode *temp = new clientStreamNode(func, nullptr, rdetach, readstatus, readdata);
117 dlinkAdd(cbdataReference(temp), &temp->node, list);
118 temp->head = list;
119 clientStreamInsertHead(list, nullptr, callback, cdetach, nullptr, callbackdata);
120 temp = (clientStreamNode *)list->tail->data;
121 temp->readBuffer = tailBuffer;
122}
123
130void
131clientStreamInsertHead(dlink_list * list, CSR * func, CSCB * callback,
132 CSD * detach, CSS * status, ClientStreamData data)
133{
134 /* test preconditions */
135 assert(list != nullptr);
136 assert(list->head);
137 clientStreamNode *temp = new clientStreamNode(func, callback, detach, status, data);
138 temp->head = list;
139 debugs(87, 3, "clientStreamInsertHead: Inserted node " << temp <<
140 " with data " << data.getRaw() << " after head");
141
142 if (list->head->next)
143 temp->readBuffer = ((clientStreamNode *)list->head->next->data)->readBuffer;
144
145 dlinkAddAfter(cbdataReference(temp), &temp->node, list->head, list);
146}
147
148// API
149void
151 HttpReply * rep, StoreIOBuffer replyBuffer)
152{
153 clientStreamNode *next;
154 assert(thisObject && http && thisObject->node.next);
155 next = thisObject->next();
156
157 debugs(87, 3, "clientStreamCallback: Calling " << next->callback << " with cbdata " <<
158 next->data.getRaw() << " from node " << thisObject);
159 next->callback(next, http, rep, replyBuffer);
160}
161
170void
172 StoreIOBuffer readBuffer)
173{
174 /* place the parameters on the 'stack' */
175 clientStreamNode *prev;
176 assert(thisObject && http && thisObject->prev());
177 prev = thisObject->prev();
178
179 debugs(87, 3, "clientStreamRead: Calling " << prev->readfunc <<
180 " with cbdata " << prev->data.getRaw() << " from node " << thisObject);
181 thisObject->readBuffer = readBuffer;
182 prev->readfunc(prev, http);
183}
184
192void
194{
195 clientStreamNode *temp = thisObject;
196
197 assert(thisObject->node.next == nullptr);
198 debugs(87, 3, "clientStreamDetach: Detaching node " << thisObject);
199 /* And clean up thisObject node */
200 /* ESI TODO: push refcount class through to head */
201 clientStreamNode *prev = nullptr;
202
203 if (thisObject->prev())
204 prev = cbdataReference(thisObject->prev());
205
206 thisObject->removeFromStream();
207
209
210 delete thisObject;
211
212 /* and tell the prev that the detach has occurred */
213 /*
214 * We do it in thisObject order so that the detaching node is always
215 * at the end of the list
216 */
217
218 if (prev) {
219 debugs(87, 3, "clientStreamDetach: Calling " << prev->detach << " with cbdata " << prev->data.getRaw());
220
221 if (cbdataReferenceValid(prev))
222 prev->detach(prev, http);
223
225 }
226}
227
235void
237{
238 dlink_list *list;
239
240 assert(thisObject != nullptr);
241 assert(http != nullptr);
242 list = thisObject->head;
243 debugs(87, 3, "clientStreamAbort: Aborting stream with tail " << list->tail);
244
245 if (list->tail) {
247 }
248}
249
259{
260 clientStreamNode *prev;
261 assert(thisObject && http && thisObject->node.prev);
262 prev = (clientStreamNode *)thisObject->node.prev->data;
263 return prev->status(prev, http);
264}
265
266void
268{
269 if (head)
271
272 head = nullptr;
273}
274
277{
278 if (node.prev)
279 return (clientStreamNode *)node.prev->data;
280 else
281 return nullptr;
282}
283
286{
287 if (node.next)
288 return (clientStreamNode *)node.next->data;
289 else
290 return nullptr;
291}
292
squidaio_request_t * head
Definition: aiops.cc:127
#define assert(EX)
Definition: assert.h:17
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:265
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:320
C * getRaw() const
Definition: RefCount.h:80
StoreIOBuffer readBuffer
Definition: clientStream.h:94
ClientStreamData data
Definition: clientStream.h:93
clientStreamNode * next() const
clientStreamNode(CSR *aReadfunc, CSCB *aCallback, CSD *aDetach, CSS *aStatus, ClientStreamData)
Definition: clientStream.cc:86
dlink_node node
Definition: clientStream.h:87
clientStreamNode * prev() const
dlink_list * head
Definition: clientStream.h:88
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
void CSCB(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer)
client stream read callback
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:193
clientStream_status_t
Definition: enums.h:125
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
void clientStreamAbort(clientStreamNode *thisObject, ClientHttpRequest *http)
clientStream_status_t clientStreamStatus(clientStreamNode *thisObject, ClientHttpRequest *http)
void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer)
void clientStreamInit(dlink_list *list, CSR *func, CSD *rdetach, CSS *readstatus, ClientStreamData readdata, CSCB *callback, CSD *cdetach, ClientStreamData callbackdata, StoreIOBuffer tailBuffer)
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
Definition: parse.c:104
struct node * next
Definition: parse.c:105

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors