MCPcopy Create free account
hub / github.com/apache/trafficserver / InterceptTransferData

Function InterceptTransferData

example/plugins/c-api/intercept/intercept.cc:236–271  ·  view source on GitHub ↗

This function is called in response to a READ_READY event. We should transfer any data we find from one side of the transfer to the other.

Source from the content-addressed store, hash-verified

234// should transfer any data we find from one side of the transfer
235// to the other.
236static int64_t
237InterceptTransferData(InterceptIO *from, InterceptIO *to)
238{
239 TSIOBufferBlock block;
240 int64_t consumed = 0;
241
242 // Walk the list of buffer blocks in from the read VIO.
243 for (block = TSIOBufferReaderStart(from->readio.reader); block; block = TSIOBufferBlockNext(block)) {
244 int64_t remain = 0;
245 const char *ptr;
246
247 VDEBUG("attempting to transfer %" PRId64 " available bytes", TSIOBufferBlockReadAvail(block, from->readio.reader));
248
249 // Take the data from each buffer block, and write it into
250 // the buffer of the write VIO.
251 ptr = TSIOBufferBlockReadStart(block, from->readio.reader, &remain);
252 while (ptr && remain) {
253 int64_t nbytes;
254
255 nbytes = TSIOBufferWrite(to->writeio.iobuf, ptr, remain);
256 remain -= nbytes;
257 ptr += nbytes;
258 consumed += nbytes;
259 }
260 }
261
262 VDEBUG("consumed %" PRId64 " bytes reading from vc=%p, writing to vc=%p", consumed, from->vc, to->vc);
263 if (consumed) {
264 TSIOBufferReaderConsume(from->readio.reader, consumed);
265 // Note that we don't have to call TSIOBufferProduce here.
266 // This is because data passed into TSIOBufferWrite is
267 // automatically "produced".
268 }
269
270 return consumed;
271}
272
273// Handle events from TSHttpTxnServerIntercept. The intercept
274// starts with TS_EVENT_NET_ACCEPT, and then continues with

Callers 1

InterceptInterceptHookFunction · 0.85

Calls 6

TSIOBufferBlockReadAvailFunction · 0.85
TSIOBufferWriteFunction · 0.85
TSIOBufferReaderStartFunction · 0.50
TSIOBufferBlockNextFunction · 0.50
TSIOBufferBlockReadStartFunction · 0.50
TSIOBufferReaderConsumeFunction · 0.50

Tested by

no test coverage detected