| 7715 | static int64_t append_buffer_length; |
| 7716 | |
| 7717 | static void |
| 7718 | handle_transform(TSCont contp) |
| 7719 | { |
| 7720 | TSVConn output_conn; |
| 7721 | TSVIO write_vio; |
| 7722 | int64_t towrite; |
| 7723 | int64_t avail; |
| 7724 | |
| 7725 | /* Get the output connection where we'll write data to. */ |
| 7726 | output_conn = TSTransformOutputVConnGet(contp); |
| 7727 | |
| 7728 | /* Get the write VIO for the write operation that was performed on |
| 7729 | ourself. This VIO contains the buffer that we are to read from |
| 7730 | as well as the continuation we are to call when the buffer is |
| 7731 | empty. */ |
| 7732 | write_vio = TSVConnWriteVIOGet(contp); |
| 7733 | |
| 7734 | /* Get our data structure for this operation. The private data |
| 7735 | structure contains the output VIO and output buffer. |
| 7736 | */ |
| 7737 | auto *data = static_cast<AppendTransformTestData *>(TSContDataGet(contp)); |
| 7738 | if (!data->output_buffer) { |
| 7739 | towrite = TSVIONBytesGet(write_vio); |
| 7740 | if (towrite != INT64_MAX) { |
| 7741 | towrite += append_buffer_length; |
| 7742 | } |
| 7743 | data->output_buffer = TSIOBufferCreate(); |
| 7744 | data->output_reader = TSIOBufferReaderAlloc(data->output_buffer); |
| 7745 | data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader, towrite); |
| 7746 | } |
| 7747 | ink_assert(data->output_vio); |
| 7748 | |
| 7749 | /* We also check to see if the write VIO's buffer is non-NULL. A |
| 7750 | NULL buffer indicates that the write operation has been |
| 7751 | shutdown and that the continuation does not want us to send any |
| 7752 | more WRITE_READY or WRITE_COMPLETE events. For this simplistic |
| 7753 | transformation that means we're done. In a more complex |
| 7754 | transformation we might have to finish writing the transformed |
| 7755 | data to our output connection. */ |
| 7756 | if (!TSVIOBufferGet(write_vio)) { |
| 7757 | if (data->append_needed) { |
| 7758 | data->append_needed = 0; |
| 7759 | TSIOBufferCopy(TSVIOBufferGet(data->output_vio), append_buffer_reader, append_buffer_length, 0); |
| 7760 | } |
| 7761 | |
| 7762 | TSVIONBytesSet(data->output_vio, TSVIONDoneGet(write_vio) + append_buffer_length); |
| 7763 | TSVIOReenable(data->output_vio); |
| 7764 | return; |
| 7765 | } |
| 7766 | |
| 7767 | /* Determine how much data we have left to read. For this append |
| 7768 | transform plugin this is also the amount of data we have left |
| 7769 | to write to the output connection. */ |
| 7770 | towrite = TSVIONTodoGet(write_vio); |
| 7771 | if (towrite > 0) { |
| 7772 | /* The amount of data left to read needs to be truncated by |
| 7773 | the amount of data actually in the read buffer. */ |
| 7774 | avail = TSIOBufferReaderAvail(TSVIOReaderGet(write_vio)); |
no test coverage detected