clientStream.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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(NULL),
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 = NULL;
101 }
102 
111 void
112 clientStreamInit(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, NULL, rdetach, readstatus, readdata);
117  dlinkAdd(cbdataReference(temp), &temp->node, list);
118  temp->head = list;
119  clientStreamInsertHead(list, NULL, callback, cdetach, NULL, callbackdata);
120  temp = (clientStreamNode *)list->tail->data;
121  temp->readBuffer = tailBuffer;
122 }
123 
130 void
133 {
134  /* test preconditions */
135  assert(list != NULL);
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 {
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 
170 void
173 {
174  /* place the parameters on the 'stack' */
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 
192 void
194 {
195  clientStreamNode *temp = thisObject;
196 
197  assert(thisObject->node.next == NULL);
198  debugs(87, 3, "clientStreamDetach: Detaching node " << thisObject);
199  /* And clean up thisObject node */
200  /* ESI TODO: push refcount class through to head */
202 
203  if (thisObject->prev())
204  prev = cbdataReference(thisObject->prev());
205 
206  thisObject->removeFromStream();
207 
208  cbdataReferenceDone(temp);
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 
224  cbdataReferenceDone(prev);
225  }
226 }
227 
235 void
237 {
238  dlink_list *list;
239 
240  assert(thisObject != NULL);
241  assert(http != NULL);
242  list = thisObject->head;
243  debugs(87, 3, "clientStreamAbort: Aborting stream with tail " << list->tail);
244 
245  if (list->tail) {
246  clientStreamDetach((clientStreamNode *)list->tail->data, http);
247  }
248 }
249 
259 {
261  assert(thisObject && http && thisObject->node.prev);
262  prev = (clientStreamNode *)thisObject->node.prev->data;
263  return prev->status(prev, http);
264 }
265 
266 void
268 {
269  if (head)
270  dlinkDelete(&node, head);
271 
272  head = NULL;
273 }
274 
277 {
278  if (node.prev)
279  return (clientStreamNode *)node.prev->data;
280  else
281  return NULL;
282 }
283 
286 {
287  if (node.next)
288  return (clientStreamNode *)node.next->data;
289  else
290  return NULL;
291 }
292 
#define assert(EX)
Definition: assert.h:17
void const char HLPCB * callback
Definition: stub_helper.cc:16
void clientStreamInit(dlink_list *list, CSR *func, CSD *rdetach, CSS *readstatus, ClientStreamData readdata, CSCB *callback, CSD *cdetach, ClientStreamData callbackdata, StoreIOBuffer tailBuffer)
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
clientStreamNode(CSR *aReadfunc, CSCB *aCallback, CSD *aDetach, CSS *aStatus, ClientStreamData)
Definition: clientStream.cc:86
void clientStreamAbort(clientStreamNode *thisObject, ClientHttpRequest *http)
void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer)
clientStream_status_t clientStreamStatus(clientStreamNode *thisObject, ClientHttpRequest *http)
void const char HLPCB void * data
Definition: stub_helper.cc:16
Definition: parse.c:104
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
#define cbdataReference(var)
Definition: cbdata.h:341
dlink_node node
Definition: clientStream.h:88
void CSCB(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer)
client stream read callback
clientStreamNode * prev() const
clientStreamNode * next() const
ClientStreamData data
Definition: clientStream.h:94
clientStream_status_t
Definition: enums.h:121
StoreIOBuffer readBuffer
Definition: clientStream.h:95
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
C * getRaw() const
Definition: RefCount.h:74
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
struct node * next
Definition: parse.c:105
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
void EVH * func
Definition: stub_event.cc:16
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
dlink_list * head
Definition: clientStream.h:89
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
squidaio_request_t * head
Definition: aiops.cc:127
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors