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, thisObject << " gives " << next->data << ' ' << replyBuffer);
158 next->callback(next, http, rep, replyBuffer);
159}
160
169void
171 StoreIOBuffer readBuffer)
172{
173 /* place the parameters on the 'stack' */
174 clientStreamNode *prev;
175 assert(thisObject && http && thisObject->prev());
176 prev = thisObject->prev();
177
178 debugs(87, 3, "clientStreamRead: Calling " << prev->readfunc <<
179 " with cbdata " << prev->data.getRaw() << " from node " << thisObject);
180 thisObject->readBuffer = readBuffer;
181 prev->readfunc(prev, http);
182}
183
191void
193{
194 clientStreamNode *temp = thisObject;
195
196 assert(thisObject->node.next == nullptr);
197 debugs(87, 3, "clientStreamDetach: Detaching node " << thisObject);
198 /* And clean up thisObject node */
199 /* ESI TODO: push refcount class through to head */
200 clientStreamNode *prev = nullptr;
201
202 if (thisObject->prev())
203 prev = cbdataReference(thisObject->prev());
204
205 thisObject->removeFromStream();
206
208
209 delete thisObject;
210
211 /* and tell the prev that the detach has occurred */
212 /*
213 * We do it in thisObject order so that the detaching node is always
214 * at the end of the list
215 */
216
217 if (prev) {
218 debugs(87, 3, "clientStreamDetach: Calling " << prev->detach << " with cbdata " << prev->data.getRaw());
219
220 if (cbdataReferenceValid(prev))
221 prev->detach(prev, http);
222
224 }
225}
226
234void
236{
237 dlink_list *list;
238
239 assert(thisObject != nullptr);
240 assert(http != nullptr);
241 list = thisObject->head;
242 debugs(87, 3, "clientStreamAbort: Aborting stream with tail " << list->tail);
243
244 if (list->tail) {
246 }
247}
248
258{
259 clientStreamNode *prev;
260 assert(thisObject && http && thisObject->node.prev);
261 prev = (clientStreamNode *)thisObject->node.prev->data;
262 return prev->status(prev, http);
263}
264
265void
267{
268 if (head)
270
271 head = nullptr;
272}
273
276{
277 if (node.prev)
278 return (clientStreamNode *)node.prev->data;
279 else
280 return nullptr;
281}
282
285{
286 if (node.next)
287 return (clientStreamNode *)node.next->data;
288 else
289 return nullptr;
290}
291
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:89
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:194
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