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

Method handler

plugins/prefetch/fetch.cc:667–763  ·  view source on GitHub ↗

* @brief Continuation to perform a background fill of a URL. * * This is pretty expensive (memory allocations etc.) */

Source from the content-addressed store, hash-verified

665 * This is pretty expensive (memory allocations etc.)
666 */
667int
668BgFetch::handler(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
669{
670 BgFetch *fetch = static_cast<BgFetch *>(TSContDataGet(contp));
671 int64_t avail;
672
673 PrefetchDebug("event: %s (%d)", TSHttpEventNameLookup(event), event);
674
675 switch (event) {
676 case TS_EVENT_IMMEDIATE:
677 case TS_EVENT_TIMEOUT:
678 // Debug info for this particular bg fetch (put all debug in here please)
679 if (dbg_ctl.on()) {
680 char buf[INET6_ADDRSTRLEN];
681 const sockaddr *sockaddress = reinterpret_cast<const sockaddr *>(&fetch->client_ip);
682
683 switch (sockaddress->sa_family) {
684 case AF_INET:
685 inet_ntop(AF_INET, &(((struct sockaddr_in *)sockaddress)->sin_addr), buf, INET_ADDRSTRLEN);
686 PrefetchDebug("client IPv4 = %s", buf);
687 break;
688 case AF_INET6:
689 inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN);
690 PrefetchDebug("client IPv6 = %s", buf);
691 break;
692 case AF_UNIX:
693 char path[TS_UNIX_SIZE];
694 strncpy(path, ats_unix_cast(sockaddress)->sun_path, TS_UNIX_SIZE);
695 PrefetchDebug("client UDS = %s", path);
696 break;
697 default:
698 TSError("[%s] Unknown address family %d", PLUGIN_NAME, sockaddress->sa_family);
699 break;
700 }
701 PrefetchDebug("Starting background fetch.");
702 dumpHeaders(fetch->_headerLoc);
703 }
704
705 // Setup the NetVC for background fetch
706 TSAssert(nullptr == fetch->vc);
707 if ((fetch->vc = TSHttpConnect(reinterpret_cast<sockaddr *>(&fetch->client_ip))) != nullptr) {
708 TSHttpHdrPrint(fetch->_mbuf, fetch->_headerLoc, fetch->req_io_buf);
709 // We never send a body with the request. ToDo: Do we ever need to support that ?
710 TSIOBufferWrite(fetch->req_io_buf, "\r\n", 2);
711
712 fetch->r_vio = TSVConnRead(fetch->vc, contp, fetch->resp_io_buf, INT64_MAX);
713 fetch->w_vio = TSVConnWrite(fetch->vc, contp, fetch->req_io_buf_reader, TSIOBufferReaderAvail(fetch->req_io_buf_reader));
714 } else {
715 delete fetch;
716 PrefetchError("Failed to connect to internal process, major malfunction");
717 }
718 break;
719
720 case TS_EVENT_VCONN_WRITE_COMPLETE:
721 // TSVConnShutdown(data->vc, 0, 1);
722 // TSVIOReenable(data->w_vio);
723 PrefetchDebug("write complete");
724 break;

Callers

nothing calls this directly

Calls 15

TSContDataGetFunction · 0.85
TSHttpEventNameLookupFunction · 0.85
ats_unix_castFunction · 0.85
dumpHeadersFunction · 0.85
TSHttpConnectFunction · 0.85
TSHttpHdrPrintFunction · 0.85
TSIOBufferWriteFunction · 0.85
TSVConnReadFunction · 0.85
TSVConnWriteFunction · 0.85
TSIOBufferReaderAvailFunction · 0.85
TSVIONDoneSetFunction · 0.85
TSVIONDoneGetFunction · 0.85

Tested by

no test coverage detected