| 56 | } |
| 57 | |
| 58 | static int |
| 59 | ts_lua_client_handler(TSCont contp, ts_lua_http_transform_ctx *transform_ctx, TSEvent event, int n) |
| 60 | { |
| 61 | TSVIO input_vio; |
| 62 | TSIOBufferReader input_reader = nullptr; |
| 63 | TSIOBufferBlock blk; |
| 64 | int64_t toread, towrite, blk_len, upstream_done, input_avail, input_wm_bytes; |
| 65 | const char *start; |
| 66 | int ret, eos, rc, top, empty_input; |
| 67 | ts_lua_coroutine *crt; |
| 68 | ts_lua_cont_info *ci; |
| 69 | |
| 70 | lua_State *L; |
| 71 | TSMutex mtxp; |
| 72 | |
| 73 | ci = &transform_ctx->cinfo; |
| 74 | crt = &ci->routine; |
| 75 | |
| 76 | mtxp = crt->mctx->mutexp; |
| 77 | L = crt->lua; |
| 78 | |
| 79 | input_vio = TSVConnWriteVIOGet(contp); |
| 80 | |
| 81 | empty_input = 0; |
| 82 | if (!TSVIOBufferGet(input_vio)) { |
| 83 | Dbg(dbg_ctl, "[%s] no input VIO and output VIO", __FUNCTION__); |
| 84 | empty_input = 1; |
| 85 | } else { // input VIO exists |
| 86 | input_wm_bytes = TSIOBufferWaterMarkGet(TSVIOBufferGet(input_vio)); |
| 87 | if (transform_ctx->upstream_watermark_bytes >= 0 && transform_ctx->upstream_watermark_bytes != input_wm_bytes) { |
| 88 | Dbg(dbg_ctl, "[%s] Setting input_vio watermark to %" PRId64 " bytes", __FUNCTION__, transform_ctx->upstream_watermark_bytes); |
| 89 | TSIOBufferWaterMarkSet(TSVIOBufferGet(input_vio), transform_ctx->upstream_watermark_bytes); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (empty_input == 0) { |
| 94 | input_reader = TSVIOReaderGet(input_vio); |
| 95 | } |
| 96 | |
| 97 | if (!transform_ctx->output.buffer) { |
| 98 | transform_ctx->output.buffer = TSIOBufferCreate(); |
| 99 | transform_ctx->output.reader = TSIOBufferReaderAlloc(transform_ctx->output.buffer); |
| 100 | |
| 101 | transform_ctx->reserved.buffer = TSIOBufferCreate(); |
| 102 | transform_ctx->reserved.reader = TSIOBufferReaderAlloc(transform_ctx->reserved.buffer); |
| 103 | |
| 104 | if (empty_input == 0) { |
| 105 | transform_ctx->upstream_bytes = TSVIONBytesGet(input_vio); |
| 106 | } else { |
| 107 | transform_ctx->upstream_bytes = 0; |
| 108 | } |
| 109 | |
| 110 | transform_ctx->downstream_bytes = INT64_MAX; |
| 111 | } |
| 112 | |
| 113 | if (empty_input == 0) { |
| 114 | input_avail = TSIOBufferReaderAvail(input_reader); |
| 115 | upstream_done = TSVIONDoneGet(input_vio); |
no test coverage detected