| 367 | } |
| 368 | |
| 369 | int |
| 370 | CacheVC::openReadFromWriterMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) |
| 371 | { |
| 372 | cancel_trigger(); |
| 373 | if (seek_to) { |
| 374 | vio.ndone = seek_to; |
| 375 | seek_to = 0; |
| 376 | } |
| 377 | IOBufferBlock *b = nullptr; |
| 378 | int64_t ntodo = vio.ntodo(); |
| 379 | if (ntodo <= 0) { |
| 380 | return EVENT_CONT; |
| 381 | } |
| 382 | if (length < (static_cast<int64_t>(doc_len)) - vio.ndone) { |
| 383 | DDbg(dbg_ctl_cache_read_agg, "truncation %X", first_key.slice32(1)); |
| 384 | if (is_action_tag_set("cache")) { |
| 385 | ink_release_assert(false); |
| 386 | } |
| 387 | Warning("Document %X truncated at %" PRId64 " of %" PRIu64 ", reading from writer", first_key.slice32(1), vio.ndone, doc_len); |
| 388 | return calluser(VC_EVENT_ERROR); |
| 389 | } |
| 390 | /* its possible that the user did a do_io_close before |
| 391 | openWriteWriteDone was called. */ |
| 392 | if (length > (static_cast<int64_t>(doc_len)) - vio.ndone) { |
| 393 | int64_t skip_bytes = length - (doc_len - vio.ndone); |
| 394 | iobufferblock_skip(writer_buf.get(), &writer_offset, &length, skip_bytes); |
| 395 | } |
| 396 | int64_t bytes = length; |
| 397 | if (bytes > vio.ntodo()) { |
| 398 | bytes = vio.ntodo(); |
| 399 | } |
| 400 | if (vio.ndone >= static_cast<int64_t>(doc_len)) { |
| 401 | ink_assert(bytes <= 0); |
| 402 | // reached the end of the document and the user still wants more |
| 403 | return calluser(VC_EVENT_EOS); |
| 404 | } |
| 405 | b = iobufferblock_clone(writer_buf.get(), writer_offset, bytes); |
| 406 | writer_buf = iobufferblock_skip(writer_buf.get(), &writer_offset, &length, bytes); |
| 407 | vio.get_writer()->append_block(b); |
| 408 | vio.ndone += bytes; |
| 409 | if (vio.ntodo() <= 0) { |
| 410 | return calluser(VC_EVENT_READ_COMPLETE); |
| 411 | } else { |
| 412 | return calluser(VC_EVENT_READ_READY); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | int |
| 417 | CacheVC::openReadClose(int event, Event * /* e ATS_UNUSED */) |
nothing calls this directly
no test coverage detected