Lines Matching refs:hChannel
96 HChannel hChannel = (HChannel)v.second;
97 if (!hChannel->isDead) {
98 FreeChannel(hChannel->channelId);
117 HChannel hChannel = (HChannel)tcp->data;
118 HdcChannelBase *thisClass = (HdcChannelBase *)hChannel->clsChannel;
119 uint32_t channelId = hChannel->channelId;
137 hChannel->availTailIndex += nread;
139 while (hChannel->availTailIndex > DWORD_SERIALIZE_SIZE) {
140 size = ntohl(*reinterpret_cast<uint32_t *>(hChannel->ioBuf + indexBuf)); // big endian
146 if (hChannel->availTailIndex - DWORD_SERIALIZE_SIZE < size) {
149 childRet = thisClass->ReadChannel(hChannel, reinterpret_cast<uint8_t *>(hChannel->ioBuf) +
153 childRet, channelId, hChannel->keepAlive);
154 if (!hChannel->keepAlive) {
160 hChannel->availTailIndex -= (DWORD_SERIALIZE_SIZE + size);
163 if (indexBuf > 0 && hChannel->availTailIndex > 0) {
164 if (memmove_s(hChannel->ioBuf, hChannel->bufSize, hChannel->ioBuf + indexBuf, hChannel->availTailIndex)) {
172 thisClass->FreeChannel(hChannel->channelId);
179 HChannel hChannel = (HChannel)req->handle->data;
180 --hChannel->ref;
181 HdcChannelBase *thisClass = (HdcChannelBase *)hChannel->clsChannel;
183 hChannel->writeFailedTimes++;
185 if (!hChannel->isDead && !hChannel->ref) {
186 thisClass->FreeChannel(hChannel->channelId);
270 void HdcChannelBase::SendChannelWithCmd(HChannel hChannel, const uint16_t commandFlag, uint8_t *bufPtr, const int size)
288 SendChannel(hChannel, data, size + sizeof(commandFlag));
295 HChannel hChannel = reinterpret_cast<HChannel>(AdminChannel(OP_QUERY_REF, channelId, nullptr));
296 if (!hChannel) {
297 WRITE_LOG(LOG_FATAL, "SendWithCmd hChannel nullptr channelId:%u", channelId);
301 if (hChannel->isDead) {
305 SendChannelWithCmd(hChannel, commandFlag, bufPtr, size);
307 --hChannel->ref;
310 void HdcChannelBase::SendChannel(HChannel hChannel, uint8_t *bufPtr, const int size)
324 if (hChannel->hWorkThread == uv_thread_self()) {
325 sendStream = (uv_stream_t *)&hChannel->hWorkTCP;
327 sendStream = (uv_stream_t *)&hChannel->hChildWorkTCP;
330 ++hChannel->ref;
341 HChannel hChannel = reinterpret_cast<HChannel>(AdminChannel(OP_QUERY_REF, channelId, nullptr));
342 if (!hChannel) {
343 WRITE_LOG(LOG_FATAL, "Send hChannel nullptr channelId:%u", channelId);
347 if (hChannel->isDead) {
351 SendChannel(hChannel, bufPtr, size);
353 --hChannel->ref;
380 auto hChannel = new HdcChannel();
381 if (!hChannel) {
385 hChannel->stdinTty.data = nullptr;
386 hChannel->stdoutTty.data = nullptr;
389 hChannel->serverOrClient = isServerOrClient;
392 uv_tcp_init(loopMain, &hChannel->hWorkTCP);
393 ++hChannel->uvHandleRef;
394 hChannel->hWorkThread = uv_thread_self();
395 hChannel->hWorkTCP.data = hChannel;
396 hChannel->clsChannel = this;
397 hChannel->channelId = channelId;
398 (void)memset_s(&hChannel->hChildWorkTCP, sizeof(hChannel->hChildWorkTCP), 0, sizeof(uv_tcp_t));
399 AdminChannel(OP_ADD, channelId, hChannel);
400 *hOutChannel = hChannel;
412 HChannel hChannel = (HChannel)handle->data;
413 HdcChannelBase *thisClass = (HdcChannelBase *)hChannel->clsChannel;
414 if (hChannel->uvHandleRef > 0) {
415 if (hChannel->serverOrClient) {
417 hChannel->uvHandleRef, hChannel->channelId, hChannel->targetSessionId);
420 hChannel->uvHandleRef, hChannel->channelId, hChannel->targetSessionId);
424 thisClass->NotifyInstanceChannelFree(hChannel);
425 thisClass->AdminChannel(OP_REMOVE, hChannel->channelId, nullptr);
427 if (!hChannel->serverOrClient) {
429 hChannel->channelId, hChannel->targetSessionId);
433 hChannel->channelId, hChannel->targetSessionId);
436 Base::TryCloseHandle((const uv_handle_t *)&hChannel->hChildWorkTCP);
438 delete hChannel;
442 void HdcChannelBase::FreeChannelContinue(HChannel hChannel)
453 hChannel->availTailIndex = 0;
454 if (hChannel->ioBuf) {
455 delete[] hChannel->ioBuf;
456 hChannel->ioBuf = nullptr;
458 if (!hChannel->serverOrClient) {
459 Base::TryCloseHandle((uv_handle_t *)&hChannel->stdinTty, closeChannelHandle);
460 Base::TryCloseHandle((uv_handle_t *)&hChannel->stdoutTty, closeChannelHandle);
462 if (uv_is_closing((const uv_handle_t *)&hChannel->hWorkTCP)) {
463 --hChannel->uvHandleRef;
465 Base::TryCloseHandle((uv_handle_t *)&hChannel->hWorkTCP, closeChannelHandle);
467 Base::IdleUvTask(loopMain, hChannel, FreeChannelFinally);
472 HChannel hChannel = (HChannel)handle->data;
473 HdcChannelBase *thisClass = (HdcChannelBase *)hChannel->clsChannel;
474 if (hChannel->ref > 0) {
477 thisClass->DispMntnInfo(hChannel);
478 if (hChannel->hChildWorkTCP.loop) {
479 auto ctrl = HdcSessionBase::BuildCtrlString(SP_DEATCH_CHANNEL, hChannel->channelId, nullptr, 0);
480 bool ret = thisClass->ChannelSendSessionCtrlMsg(ctrl, hChannel->targetSessionId);
483 hChannel->channelId, hChannel->targetSessionId);
484 hChannel->childCleared = true;
487 HChannel hChannel = (HChannel)handle->data;
488 HdcChannelBase *thisClass = (HdcChannelBase *)hChannel->clsChannel;
489 if (!hChannel->childCleared) {
491 hChannel->childCleared, hChannel->channelId, hChannel->targetSessionId);
495 thisClass->FreeChannelContinue(hChannel);
497 Base::TimerUvTask(thisClass->loopMain, hChannel, callbackCheckFreeChannelContinue);
499 thisClass->FreeChannelContinue(hChannel);
511 HChannel hChannel = AdminChannel(OP_QUERY, channelId, nullptr);
513 if (!hChannel || hChannel->isDead) {
514 WRITE_LOG(LOG_WARN, "FreeChannel hChannel nullptr or isDead channelid:%u", channelId);
518 Base::TimerUvTask(loopMain, hChannel, FreeChannelOpeate, MINOR_TIMEOUT); // do immediately
519 hChannel->isDead = true;
565 void HdcChannelBase::EchoToClient(HChannel hChannel, uint8_t *bufPtr, const int size)
579 sendStream = (uv_stream_t *)&hChannel->hChildWorkTCP;
581 ++hChannel->ref;
584 WRITE_LOG(LOG_WARN, "EchoToClient, channelId:%u is unwritable.", hChannel->channelId);
592 HChannel hChannel = (HChannel)v.second;
593 if (!hChannel->isDead && hChannel->targetSessionId == targetSessionId) {
595 EchoToClient(hChannel, (uint8_t *)echo.c_str(), echo.size());
600 void HdcChannelBase::DispMntnInfo(HChannel hChannel)
602 if (!hChannel) {
607 hChannel->channelId, hChannel->isDead, uint32_t(hChannel->ref), uint32_t(hChannel->writeFailedTimes));