Lines Matching refs:ctx
46 HCtxForward ctx = iter->second;
47 ctxs.push_back(ctx);
52 for (auto ctx: ctxs) {
53 FreeContext(ctx, 0, false);
118 HCtxForward ctx = nullptr;
119 if ((ctx = new ContextForward()) == nullptr) {
122 ctx->id = Base::GetRandomU32();
123 ctx->masterSlave = masterSlave;
124 ctx->thisClass = this;
125 ctx->fdClass = nullptr;
126 ctx->tcp.data = ctx;
127 ctx->pipe.data = ctx;
128 AdminContext(OP_ADD, ctx->id, ctx);
130 return ctx;
133 void HdcForwardBase::FreeContextCallBack(HCtxForward ctx)
135 Base::DoNextLoop(loopTask, ctx, [this](const uint8_t flag, string &msg, const void *data) {
136 HCtxForward ctx = (HCtxForward)data;
137 AdminContext(OP_REMOVE, ctx->id, nullptr);
138 if (ctx != nullptr) {
139 WRITE_LOG(LOG_DEBUG, "Finally to delete id:%u", ctx->id);
140 delete ctx;
141 ctx = nullptr;
149 void HdcForwardBase::FreeJDWP(HCtxForward ctx)
151 Base::CloseFd(ctx->fd);
152 if (ctx->fdClass) {
153 ctx->fdClass->StopWorkOnThread(false, nullptr);
157 HCtxForward ctx = (HCtxForward)handle->data;
158 ctx->thisClass->FreeContextCallBack(ctx);
168 Base::IdleUvTask(loopTask, ctx, funcReqClose);
175 HCtxForward ctx = nullptr;
177 if (!(ctx = (HCtxForward)AdminContext(OP_QUERY, id, nullptr))) {
182 ctx = ctxIn;
185 ctx->id, bNotifyRemote, ctx->finish);
186 if (ctx->finish) {
190 SendToTask(ctx->id, CMD_FORWARD_FREE_CONTEXT, nullptr, 0);
193 HCtxForward ctx = (HCtxForward)handle->data;
194 ctx->thisClass->FreeContextCallBack(ctx);
196 switch (ctx->type) {
200 Base::TryCloseHandle((uv_handle_t *)&ctx->tcp, true, funcHandleClose);
205 Base::TryCloseHandle((uv_handle_t *)&ctx->pipe, true, funcHandleClose);
208 FreeJDWP(ctx);
214 ctx->finish = true;
257 HCtxForward ctx = (HCtxForward)stream->data;
259 WRITE_LOG(LOG_INFO, "ReadForwardBuf nread:%zd id:%u", nread, ctx->id);
260 ctx->thisClass->FreeContext(ctx, 0, true);
265 WRITE_LOG(LOG_INFO, "ReadForwardBuf nread:0 id:%u", ctx->id);
269 ctx->thisClass->SendToTask(ctx->id, CMD_FORWARD_DATA, (uint8_t *)buf->base, nread);
276 HCtxForward ctx = (HCtxForward)connection->data;
277 HdcForwardBase *thisClass = ctx->thisClass;
285 thisClass->SetupPointContinue(ctx, status);
317 bool HdcForwardBase::SetupPointContinue(HCtxForward ctx, int status)
319 if (ctx->checkPoint) {
322 SendToTask(ctx->id, CMD_FORWARD_CHECK_RESULT, &flag, 1);
323 FreeContext(ctx, 0, false);
327 FreeContext(ctx, 0, true);
331 if (!SendToTask(ctx->id, CMD_FORWARD_ACTIVE_MASTER, nullptr, 0)) {
332 WRITE_LOG(LOG_FATAL, "SetupPointContinue SendToTask failed id:%u", ctx->id);
333 FreeContext(ctx, 0, true);
336 return DoForwardBegin(ctx);
406 HCtxForward ctx = (HCtxForward)a;
407 return SendToTask(ctx->id, CMD_FORWARD_DATA, b, c);
410 HCtxForward ctx = (HCtxForward)a;
411 WRITE_LOG(LOG_DEBUG, "funcFinish id:%u ret:%d reason:%s", ctx->id, b, c.c_str());
412 FreeContext(ctx, 0, true);
664 bool HdcForwardBase::DoForwardBegin(HCtxForward ctx)
666 switch (ctx->type) {
669 uv_tcp_nodelay((uv_tcp_t *)&ctx->tcp, 1);
670 uv_read_start((uv_stream_t *)&ctx->tcp, AllocForwardBuf, ReadForwardBuf);
673 WRITE_LOG(LOG_DEBUG, "DoForwardBegin ark socketpair id:%u fds[0]:%d", ctx->id, fds[0]);
674 uv_tcp_init(loopTask, &ctx->tcp);
675 uv_tcp_open(&ctx->tcp, fds[0]);
676 uv_tcp_nodelay((uv_tcp_t *)&ctx->tcp, 1);
677 uv_read_start((uv_stream_t *)&ctx->tcp, AllocForwardBuf, ReadForwardBuf);
682 uv_read_start((uv_stream_t *)&ctx->pipe, AllocForwardBuf, ReadForwardBuf);
685 ctx->fdClass->StartWorkOnThread();
691 ctx->ready = true;
726 HCtxForward ctx = reinterpret_cast<HCtxForward>(ctxIO->ctxForward);
727 if (status < 0 && !ctx->finish) {
728 WRITE_LOG(LOG_DEBUG, "SendCallbackForwardBuf ctx->type:%d, status:%d finish", ctx->type, status);
729 ctx->thisClass->FreeContext(ctx, 0, true);
736 int HdcForwardBase::SendForwardBuf(HCtxForward ctx, uint8_t *bufPtr, const int size)
740 WRITE_LOG(LOG_WARN, "SendForwardBuf size:%d > HDC_BUF_MAX_BYTES, ctxId:%u", size, ctx->id);
744 WRITE_LOG(LOG_WARN, "SendForwardBuf failed size:%d, ctxId:%u", size, ctx->id);
749 WRITE_LOG(LOG_WARN, "SendForwardBuf new DynBuf failed size:%d, ctxId:%u", size, ctx->id);
753 if (ctx->type == FORWARD_DEVICE) {
754 nRet = ctx->fdClass->WriteWithMem(pDynBuf, size);
758 WRITE_LOG(LOG_WARN, "SendForwardBuf new ContextForwardIO failed, ctxId:%u", ctx->id);
762 ctxIO->ctxForward = ctx;
764 if (ctx->type == FORWARD_TCP || ctx->type == FORWARD_JDWP || ctx->type == FORWARD_ARK) {
765 nRet = Base::SendToStreamEx((uv_stream_t *)&ctx->tcp, pDynBuf, size, nullptr,
769 nRet = Base::SendToStreamEx((uv_stream_t *)&ctx->pipe, pDynBuf, size, nullptr,
774 nRet, size, ctx->id, ctx->type);
780 bool HdcForwardBase::CommandForwardCheckResult(HCtxForward ctx, uint8_t *payload)
788 ctx->ready = true;
793 FreeContext(ctx, 0, false);
809 HCtxForward ctx = nullptr;
812 if (!(ctx = (HCtxForward)AdminContext(OP_QUERY, id, nullptr))) {
818 ret = CommandForwardCheckResult(ctx, pContent);
822 ret = DoForwardBegin(ctx);
826 if (ctx->finish) {
829 if (SendForwardBuf(ctx, pContent, sizeContent) < 0) {
830 WRITE_LOG(LOG_WARN, "ForwardCommandDispatch SendForwardBuf rc < 0, ctxid:%u", ctx->id);
831 FreeContext(ctx, 0, true);
836 FreeContext(ctx, 0, false);
844 if (ctx) {
845 FreeContext(ctx, 0, true);
847 WRITE_LOG(LOG_DEBUG, "ctx==nullptr raw free");