this is when the client starts asking us for more data
| 122 | |
| 123 | // this is when the client starts asking us for more data |
| 124 | void |
| 125 | handle_client_resp(TSCont contp, TSEvent event, Data *const data) |
| 126 | { |
| 127 | switch (event) { |
| 128 | case TS_EVENT_VCONN_WRITE_READY: { |
| 129 | switch (data->m_blockstate) { |
| 130 | case BlockState::Fail: |
| 131 | case BlockState::PendingRef: |
| 132 | case BlockState::ActiveRef: { |
| 133 | TSVIO const output_vio = data->m_dnstream.m_write.m_vio; |
| 134 | int64_t const output_done = TSVIONDoneGet(output_vio); |
| 135 | int64_t const output_sent = data->m_bytessent; |
| 136 | |
| 137 | if (output_sent == output_done) { |
| 138 | DEBUG_LOG("Downstream output is done, shutting down"); |
| 139 | shutdown(contp, data); |
| 140 | } |
| 141 | } break; |
| 142 | |
| 143 | case BlockState::Pending: { |
| 144 | // throttle |
| 145 | TSVIO const output_vio = data->m_dnstream.m_write.m_vio; |
| 146 | int64_t const output_done = TSVIONDoneGet(output_vio); |
| 147 | int64_t const output_sent = data->m_bytessent; |
| 148 | int64_t const threshout = data->m_config->m_blockbytes; |
| 149 | int64_t const buffered = output_sent - output_done; |
| 150 | |
| 151 | if (threshout < buffered) { |
| 152 | DEBUG_LOG("%p handle_client_resp: throttling %" PRId64, data, buffered); |
| 153 | } else { |
| 154 | DEBUG_LOG("Starting next block request"); |
| 155 | if (!request_block(contp, data)) { |
| 156 | data->m_blockstate = BlockState::Fail; |
| 157 | return; |
| 158 | } |
| 159 | } |
| 160 | } break; |
| 161 | case BlockState::Passthru: { |
| 162 | } break; |
| 163 | default: |
| 164 | break; |
| 165 | } |
| 166 | } break; |
| 167 | case TS_EVENT_VCONN_WRITE_COMPLETE: { |
| 168 | if (dbg_ctl.on() && reader_avail_more_than(data->m_upstream.m_read.m_reader, 0)) { |
| 169 | int64_t const left = TSIOBufferReaderAvail(data->m_upstream.m_read.m_reader); |
| 170 | DEBUG_LOG("%p WRITE_COMPLETE called with %" PRId64 " bytes left", data, left); |
| 171 | } |
| 172 | |
| 173 | data->m_dnstream.close(); |
| 174 | if (!data->m_upstream.m_read.isOpen()) { |
| 175 | shutdown(contp, data); |
| 176 | } |
| 177 | } break; |
| 178 | default: { |
| 179 | DEBUG_LOG("%p handle_client_resp unhandled event %d %s", data, event, TSHttpEventNameLookup(event)); |
| 180 | } break; |
| 181 | } |
no test coverage detected