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

Function handle_io

example/plugins/c-api/cache_scan/cache_scan.cc:255–306  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

253
254//----------------------------------------------------------------------------
255static int
256handle_io(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
257{
258 cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp));
259
260 switch (event) {
261 case TS_EVENT_VCONN_READ_READY:
262 case TS_EVENT_VCONN_READ_COMPLETE: {
263 // we don't care about the request, so just shut down the read vc
264 TSVConnShutdown(cstate->net_vc, 1, 0);
265 // setup the response headers so we are ready to write body
266 char hdrs[] = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n";
267 cstate->total_bytes = TSIOBufferWrite(cstate->resp_buffer, hdrs, sizeof(hdrs) - 1);
268
269 if (cstate->key_to_delete) {
270 TSAction actionp = TSCacheRemove(contp, cstate->key_to_delete);
271 if (!TSActionDone(actionp)) {
272 cstate->pending_action = actionp;
273 }
274 } else {
275 char head[] = "<h3>Cache Contents:</h3>\n<p><pre>\n";
276 cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, head, sizeof(head) - 1);
277 // start scan
278 TSAction actionp = TSCacheScan(contp, nullptr, 512000);
279 if (!TSActionDone(actionp)) {
280 cstate->pending_action = actionp;
281 }
282 }
283
284 return 0;
285 } break;
286 case TS_EVENT_VCONN_WRITE_READY: {
287 Dbg(dbg_ctl, "ndone: %" PRId64 " total_bytes: % " PRId64, TSVIONDoneGet(cstate->write_vio), cstate->total_bytes);
288 cstate->write_pending = false;
289 // the cache scan handler should call vio reenable when there is
290 // available data
291 return 0;
292 } break;
293 case TS_EVENT_VCONN_WRITE_COMPLETE: {
294 Dbg(dbg_ctl, "write complete");
295 cstate->done = 1;
296 cleanup(contp);
297 } break;
298 case TS_EVENT_VCONN_EOS:
299 default: {
300 cstate->done = 1;
301 cleanup(contp);
302 } break;
303 }
304
305 return 0;
306}
307
308//----------------------------------------------------------------------------
309// handler for VConnection and CacheScan events

Callers 1

cache_interceptFunction · 0.85

Calls 8

TSContDataGetFunction · 0.85
TSVConnShutdownFunction · 0.85
TSIOBufferWriteFunction · 0.85
TSCacheRemoveFunction · 0.85
TSActionDoneFunction · 0.85
TSCacheScanFunction · 0.85
TSVIONDoneGetFunction · 0.85
cleanupFunction · 0.70

Tested by

no test coverage detected