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 
86 clientStreamNode::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 
111 void
112 clientStreamInit(dlink_list * list, CSR * func, CSD * rdetach, CSS * readstatus,
113  const ClientStreamData &readdata, CSCB * callback, CSD * cdetach, const 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 
130 void
131 clientStreamInsertHead(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
149 void
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 
169 void
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 
191 void
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 
207  cbdataReferenceDone(temp);
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 
223  cbdataReferenceDone(prev);
224  }
225 }
226 
234 void
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) {
245  clientStreamDetach((clientStreamNode *)list->tail->data, http);
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 
265 void
267 {
268  if (head)
269  dlinkDelete(&node, 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 
Definition: parse.c:104
clientStream_status_t clientStreamStatus(clientStreamNode *thisObject, ClientHttpRequest *http)
dlink_node node
Definition: clientStream.h:87
ClientStreamData data
Definition: clientStream.h:93
void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer)
struct node * next
Definition: parse.c:105
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
C * getRaw() const
Definition: RefCount.h:89
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:270
#define cbdataReference(var)
Definition: cbdata.h:348
clientStreamNode(CSR *aReadfunc, CSCB *aCallback, CSD *aDetach, CSS *aStatus, ClientStreamData)
Definition: clientStream.cc:86
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
dlink_list * head
Definition: clientStream.h:88
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
clientStreamNode * next() const
#define assert(EX)
Definition: assert.h:17
#define cbdataReferenceDone(var)
Definition: cbdata.h:357
clientStreamNode * prev() const
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:325
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
void clientStreamInit(dlink_list *list, CSR *func, CSD *rdetach, CSS *readstatus, const ClientStreamData &readdata, CSCB *callback, CSD *cdetach, const ClientStreamData &callbackdata, StoreIOBuffer tailBuffer)
squidaio_request_t * head
Definition: aiops.cc:127
clientStream_status_t
Definition: enums.h:120
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
StoreIOBuffer readBuffer
Definition: clientStream.h:94
void CSCB(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer)
client stream read callback
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
void clientStreamAbort(clientStreamNode *thisObject, ClientHttpRequest *http)

 

Introduction

Documentation

Support

Miscellaneous