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

Function state_write_to_cache

example/plugins/c-api/protocol/TxnSM.cc:677–730  ·  view source on GitHub ↗

If the whole doc has been written into the cache, send the response to the client, otherwise, reenable the read_vio. */

Source from the content-addressed store, hash-verified

675/* If the whole doc has been written into the cache, send the response
676 to the client, otherwise, reenable the read_vio. */
677int
678state_write_to_cache(TSCont contp, TSEvent event, TSVIO vio)
679{
680 TxnSM *txn_sm = static_cast<TxnSM *>(TSContDataGet(contp));
681
682 Dbg(dbg_ctl, "enter state_write_to_cache");
683
684 switch (event) {
685 case TS_EVENT_VCONN_WRITE_READY:
686 TSVIOReenable(txn_sm->q_cache_write_vio);
687 return TS_SUCCESS;
688
689 case TS_EVENT_VCONN_WRITE_COMPLETE:
690 Dbg(dbg_ctl, "nbytes %" PRId64 ", ndone %" PRId64, TSVIONBytesGet(vio), TSVIONDoneGet(vio));
691 /* Since the first write is through TSVConnWrite, which already consume
692 the data in cache_buffer_reader, don't consume it again. */
693 if (txn_sm->q_cache_response_length > 0 && txn_sm->q_block_bytes_read > 0) {
694 TSIOBufferReaderConsume(txn_sm->q_cache_response_buffer_reader, txn_sm->q_block_bytes_read);
695 }
696
697 txn_sm->q_cache_response_length += TSVIONBytesGet(vio);
698
699 /* If not all data have been read in, we have to reenable the read_vio */
700 if (txn_sm->q_server_vc != nullptr) {
701 Dbg(dbg_ctl, "re-enable server_read_vio");
702 TSVIOReenable(txn_sm->q_server_read_vio);
703 return TS_SUCCESS;
704 }
705
706 if (txn_sm->q_cache_response_length >= txn_sm->q_server_response_length) {
707 /* Write is complete, close the cache_vc. */
708 Dbg(dbg_ctl, "close cache_vc, cache_response_length is %d, server_response_length is %d", txn_sm->q_cache_response_length,
709 txn_sm->q_server_response_length);
710 TSVConnClose(txn_sm->q_cache_vc);
711 txn_sm->q_cache_vc = nullptr;
712 txn_sm->q_cache_write_vio = nullptr;
713 TSIOBufferReaderFree(txn_sm->q_cache_response_buffer_reader);
714
715 /* Open cache_vc to read data and send to client. */
716 set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_handle_cache_lookup);
717 txn_sm->q_pending_action = TSCacheRead(contp, txn_sm->q_key);
718 } else { /* not done with writing into cache */
719
720 Dbg(dbg_ctl, "re-enable cache_write_vio");
721 TSVIOReenable(txn_sm->q_cache_write_vio);
722 }
723 return TS_SUCCESS;
724 default:
725 break;
726 }
727
728 /* Something wrong if getting here. */
729 return prepare_to_die(contp);
730}
731
732/* If the response has been fully written into the client_vc,
733 which means this txn is done, close the client_vc. Otherwise,

Callers 1

Calls 9

TSContDataGetFunction · 0.85
TSVIOReenableFunction · 0.85
TSVIONBytesGetFunction · 0.85
TSVIONDoneGetFunction · 0.85
TSVConnCloseFunction · 0.85
TSIOBufferReaderFreeFunction · 0.85
TSCacheReadFunction · 0.85
prepare_to_dieFunction · 0.85
TSIOBufferReaderConsumeFunction · 0.50

Tested by

no test coverage detected