----------------------------------------------------------------------------
| 64 | |
| 65 | //---------------------------------------------------------------------------- |
| 66 | static int |
| 67 | handle_scan(TSCont contp, TSEvent event, void *edata) |
| 68 | { |
| 69 | cache_scan_state *cstate = static_cast<cache_scan_state *>(TSContDataGet(contp)); |
| 70 | |
| 71 | if (event == TS_EVENT_CACHE_REMOVE) { |
| 72 | cstate->done = 1; |
| 73 | const char error[] = "Cache remove operation succeeded"; |
| 74 | cstate->cache_vc = static_cast<TSVConn>(edata); |
| 75 | cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX); |
| 76 | cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1); |
| 77 | TSVIONBytesSet(cstate->write_vio, cstate->total_bytes); |
| 78 | TSVIOReenable(cstate->write_vio); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | if (event == TS_EVENT_CACHE_REMOVE_FAILED) { |
| 83 | cstate->done = 1; |
| 84 | const char error[] = "Cache remove operation failed error="; |
| 85 | char rc[12]; |
| 86 | snprintf(rc, 12, "%p", edata); |
| 87 | cstate->cache_vc = static_cast<TSVConn>(edata); |
| 88 | cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX); |
| 89 | cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1); |
| 90 | cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, rc, strlen(rc)); |
| 91 | |
| 92 | TSVIONBytesSet(cstate->write_vio, cstate->total_bytes); |
| 93 | TSVIOReenable(cstate->write_vio); |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | // first scan event, save vc and start write |
| 98 | if (event == TS_EVENT_CACHE_SCAN) { |
| 99 | cstate->cache_vc = static_cast<TSVConn>(edata); |
| 100 | cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX); |
| 101 | return TS_EVENT_CONTINUE; |
| 102 | } |
| 103 | // just stop scanning if blocked or failed |
| 104 | if (event == TS_EVENT_CACHE_SCAN_FAILED || event == TS_EVENT_CACHE_SCAN_OPERATION_BLOCKED || |
| 105 | event == TS_EVENT_CACHE_SCAN_OPERATION_FAILED) { |
| 106 | cstate->done = 1; |
| 107 | if (cstate->resp_buffer) { |
| 108 | const char error[] = "Cache scan operation blocked or failed"; |
| 109 | cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1); |
| 110 | } |
| 111 | if (cstate->write_vio) { |
| 112 | TSVIONBytesSet(cstate->write_vio, cstate->total_bytes); |
| 113 | TSVIOReenable(cstate->write_vio); |
| 114 | } |
| 115 | return TS_CACHE_SCAN_RESULT_DONE; |
| 116 | } |
| 117 | |
| 118 | // grab header and print url to outgoing vio |
| 119 | if (event == TS_EVENT_CACHE_SCAN_OBJECT) { |
| 120 | if (cstate->done) { |
| 121 | return TS_CACHE_SCAN_RESULT_DONE; |
| 122 | } |
| 123 | TSCacheHttpInfo cache_infop = static_cast<TSCacheHttpInfo>(edata); |
no test coverage detected