• Home
  • Raw
  • Download

Lines Matching refs:hSession

139 void HdcSessionBase::ClearOwnTasks(HSession hSession, const uint32_t channelIDInput)  in ClearOwnTasks()  argument
145 hSession->mapTaskMutex.lock(); in ClearOwnTasks()
147 for (iter = hSession->mapTask->begin(); iter != hSession->mapTask->end();) { in ClearOwnTasks()
156 … WRITE_LOG(LOG_DEBUG, "ClearOwnTasks OP_CLEAR finish, session:%p channelIDInput:%u", hSession, in ClearOwnTasks()
158 iter = hSession->mapTask->erase(iter); in ClearOwnTasks()
163 iter = hSession->mapTask->erase(iter); in ClearOwnTasks()
165 hSession->mapTaskMutex.unlock(); in ClearOwnTasks()
173 HSession hSession = (HSession)v.second; in ClearSessions() local
174 if (!hSession->isDead) { in ClearSessions()
175 FreeSession(hSession->sessionId); in ClearSessions()
213 void HdcSessionBase::EnumUSBDeviceRegister(void (*pCallBack)(HSession hSession)) in EnumUSBDeviceRegister() argument
352 int HdcSessionBase::MallocSessionByConnectType(HSession hSession) in MallocSessionByConnectType() argument
355 switch (hSession->connType) { in MallocSessionByConnectType()
357 uv_tcp_init(&loopMain, &hSession->hWorkTCP); in MallocSessionByConnectType()
358 ++hSession->uvHandleRef; in MallocSessionByConnectType()
359 hSession->hWorkTCP.data = hSession; in MallocSessionByConnectType()
369 hSession->hUSB = hUSB; in MallocSessionByConnectType()
370 hSession->hUSB->wMaxPacketSizeSend = MAX_PACKET_SIZE_HISPEED; in MallocSessionByConnectType()
380 hSession->hUART = hUART; in MallocSessionByConnectType()
405 HSession hSession = new(std::nothrow) HdcSession(); in MallocSession() local
406 if (!hSession) { in MallocSession()
412 hSession->classInstance = this; in MallocSession()
413 hSession->connType = connType; in MallocSession()
414 hSession->classModule = classModule; in MallocSession()
415 hSession->isDead = false; in MallocSession()
416 hSession->sessionId = ((sessionId == 0) ? GetSessionPseudoUid() : sessionId); in MallocSession()
417 hSession->serverOrDaemon = serverOrDaemon; in MallocSession()
418 hSession->hWorkThread = uv_thread_self(); in MallocSession()
419 hSession->mapTask = new(std::nothrow) map<uint32_t, HTaskInfo>(); in MallocSession()
420 if (hSession->mapTask == nullptr) { in MallocSession()
422 delete hSession; in MallocSession()
423 hSession = nullptr; in MallocSession()
426 hSession->listKey = new(std::nothrow) list<void *>; in MallocSession()
427 if (hSession->listKey == nullptr) { in MallocSession()
429 delete hSession; in MallocSession()
430 hSession = nullptr; in MallocSession()
433 uv_loop_init(&hSession->childLoop); in MallocSession()
434 hSession->uvHandleRef = 0; in MallocSession()
437 hSession->sessionId, hSession->connType); in MallocSession()
438 ++hSession->uvHandleRef; in MallocSession()
439 Base::CreateSocketPair(hSession->ctrlFd); in MallocSession()
441 hSession->pollHandle[STREAM_WORK] = (uv_poll_t *)malloc(handleSize); in MallocSession()
442 hSession->pollHandle[STREAM_MAIN] = (uv_poll_t *)malloc(handleSize); in MallocSession()
443 uv_poll_t *pollHandleMain = hSession->pollHandle[STREAM_MAIN]; in MallocSession()
444 if (pollHandleMain == nullptr || hSession->pollHandle[STREAM_WORK] == nullptr) { in MallocSession()
446 delete hSession; in MallocSession()
447 hSession = nullptr; in MallocSession()
450 uv_poll_init_socket(&loopMain, pollHandleMain, hSession->ctrlFd[STREAM_MAIN]); in MallocSession()
452 hSession->pollHandle[STREAM_MAIN]->data = hSession; in MallocSession()
453 hSession->pollHandle[STREAM_WORK]->data = hSession; in MallocSession()
455 uv_tcp_init(&loopMain, &hSession->dataPipe[STREAM_MAIN]); in MallocSession()
456 (void)memset_s(&hSession->dataPipe[STREAM_WORK], sizeof(hSession->dataPipe[STREAM_WORK]), in MallocSession()
458 ++hSession->uvHandleRef; in MallocSession()
459 Base::CreateSocketPair(hSession->dataFd); in MallocSession()
460 uv_tcp_open(&hSession->dataPipe[STREAM_MAIN], hSession->dataFd[STREAM_MAIN]); in MallocSession()
461 hSession->dataPipe[STREAM_MAIN].data = hSession; in MallocSession()
462 hSession->dataPipe[STREAM_WORK].data = hSession; in MallocSession()
463 Base::SetTcpOptions(&hSession->dataPipe[STREAM_MAIN]); in MallocSession()
464 ret = MallocSessionByConnectType(hSession); in MallocSession()
466 delete hSession; in MallocSession()
467 hSession = nullptr; in MallocSession()
469 AdminSession(OP_ADD, hSession->sessionId, hSession); in MallocSession()
471 return hSession; in MallocSession()
474 void HdcSessionBase::FreeSessionByConnectType(HSession hSession) in FreeSessionByConnectType() argument
476 WRITE_LOG(LOG_DEBUG, "FreeSessionByConnectType %s", hSession->ToDebugString().c_str()); in FreeSessionByConnectType()
478 if (CONN_USB == hSession->connType) { in FreeSessionByConnectType()
480 if (!hSession->hUSB) { in FreeSessionByConnectType()
483 HUSB hUSB = hSession->hUSB; in FreeSessionByConnectType()
497 delete hSession->hUSB; in FreeSessionByConnectType()
498 hSession->hUSB = nullptr; in FreeSessionByConnectType()
501 if (CONN_SERIAL == hSession->connType) { in FreeSessionByConnectType()
502 if (!hSession->hUART) { in FreeSessionByConnectType()
505 HUART hUART = hSession->hUART; in FreeSessionByConnectType()
509 HdcUARTBase *uartBase = (HdcUARTBase *)hSession->classModule; in FreeSessionByConnectType()
511 uartBase->StopSession(hSession); in FreeSessionByConnectType()
522 delete hSession->hUART; in FreeSessionByConnectType()
523 hSession->hUART = nullptr; in FreeSessionByConnectType()
531 HSession hSession = (HSession)handle->data; in FreeSessionFinally() local
532 HdcSessionBase *thisClass = (HdcSessionBase *)hSession->classInstance; in FreeSessionFinally()
533 if (hSession->uvHandleRef > 0) { in FreeSessionFinally()
537 thisClass->NotifyInstanceSessionFree(hSession, true); in FreeSessionFinally()
539 thisClass->AdminSession(OP_REMOVE, hSession->sessionId, nullptr); in FreeSessionFinally()
540 WRITE_LOG(LOG_DEBUG, "!!!FreeSessionFinally sessionId:%u finish", hSession->sessionId); in FreeSessionFinally()
541 HdcAuth::FreeKey(!hSession->serverOrDaemon, hSession->listKey); in FreeSessionFinally()
542 delete hSession; in FreeSessionFinally()
543 hSession = nullptr; // fix CodeMars SetNullAfterFree issue in FreeSessionFinally()
549 void HdcSessionBase::FreeSessionContinue(HSession hSession) in FreeSessionContinue() argument
552 HSession hSession = (HSession)handle->data; in FreeSessionContinue() local
553 --hSession->uvHandleRef; in FreeSessionContinue()
555 if (handle == reinterpret_cast<uv_handle_t *>(hSession->pollHandle[STREAM_MAIN])) { in FreeSessionContinue()
556 free(hSession->pollHandle[STREAM_MAIN]); in FreeSessionContinue()
559 if (CONN_TCP == hSession->connType) { in FreeSessionContinue()
561 Base::TryCloseHandle((uv_handle_t *)&hSession->hWorkTCP, true, closeSessionTCPHandle); in FreeSessionContinue()
563 hSession->availTailIndex = 0; in FreeSessionContinue()
564 if (hSession->ioBuf) { in FreeSessionContinue()
565 delete[] hSession->ioBuf; in FreeSessionContinue()
566 hSession->ioBuf = nullptr; in FreeSessionContinue()
568 …Base::TryCloseHandle((uv_handle_t *)hSession->pollHandle[STREAM_MAIN], true, closeSessionTCPHandle… in FreeSessionContinue()
569 …Base::TryCloseHandle((uv_handle_t *)&hSession->dataPipe[STREAM_MAIN], true, closeSessionTCPHandle); in FreeSessionContinue()
570 FreeSessionByConnectType(hSession); in FreeSessionContinue()
572 Base::IdleUvTask(&loopMain, hSession, FreeSessionFinally); in FreeSessionContinue()
578 HSession hSession = (HSession)handle->data; in FreeSessionOpeate() local
579 HdcSessionBase *thisClass = (HdcSessionBase *)hSession->classInstance; in FreeSessionOpeate()
580 if (hSession->ref > 0) { in FreeSessionOpeate()
583 WRITE_LOG(LOG_DEBUG, "FreeSessionOpeate ref:%u", uint32_t(hSession->ref)); in FreeSessionOpeate()
585 if (hSession->hUSB != nullptr in FreeSessionOpeate()
586 && (!hSession->hUSB->hostBulkIn.isShutdown || !hSession->hUSB->hostBulkOut.isShutdown)) { in FreeSessionOpeate()
587 HdcUSBBase *pUSB = ((HdcUSBBase *)hSession->classModule); in FreeSessionOpeate()
588 pUSB->CancelUsbIo(hSession); in FreeSessionOpeate()
593 if (hSession->pollHandle[STREAM_WORK]->loop) { in FreeSessionOpeate()
595 Base::SendToPollFd(hSession->ctrlFd[STREAM_MAIN], ctrl.data(), ctrl.size()); in FreeSessionOpeate()
596 …WRITE_LOG(LOG_DEBUG, "FreeSessionOpeate, send workthread for free. sessionId:%u", hSession->sessio… in FreeSessionOpeate()
598 HSession hSession = (HSession)handle->data; in FreeSessionOpeate() local
599 HdcSessionBase *thisClass = (HdcSessionBase *)hSession->classInstance; in FreeSessionOpeate()
600 if (!hSession->childCleared) { in FreeSessionOpeate()
604 thisClass->FreeSessionContinue(hSession); in FreeSessionOpeate()
606 Base::TimerUvTask(&thisClass->loopMain, hSession, callbackCheckFreeSessionContinue); in FreeSessionOpeate()
608 thisClass->FreeSessionContinue(hSession); in FreeSessionOpeate()
620 HSession hSession = AdminSession(OP_QUERY, sessionId, nullptr); in FreeSession() local
623 if (!hSession || hSession->isDead) { in FreeSession()
626 hSession->isDead = true; in FreeSession()
627 Base::TimerUvTask(&loopMain, hSession, FreeSessionOpeate); in FreeSession()
628 NotifyInstanceSessionFree(hSession, false); in FreeSession()
629 …WRITE_LOG(LOG_DEBUG, "FreeSession sessionId:%u ref:%u", hSession->sessionId, uint32_t(hSession->re… in FreeSession()
715 HTaskInfo HdcSessionBase::AdminTask(const uint8_t op, HSession hSession, const uint32_t channelId, … in AdminTask() argument
718 map<uint32_t, HTaskInfo> &mapTask = *hSession->mapTask; in AdminTask()
734 hSession->sessionId, channelId, mapTask.size()); in AdminTask()
740 hSession->sessionId, channelId, mapTask.size()); in AdminTask()
748 AdminSession(op, hSession->sessionId, nullptr); in AdminTask()
756 int HdcSessionBase::SendByProtocol(HSession hSession, uint8_t *bufPtr, const int bufLen, bool echo ) in SendByProtocol() argument
759 if (hSession->isDead) { in SendByProtocol()
764 switch (hSession->connType) { in SendByProtocol()
766 HdcTCPBase *pTCP = ((HdcTCPBase *)hSession->classModule); in SendByProtocol()
767 if (echo && !hSession->serverOrDaemon) { in SendByProtocol()
768 ret = pTCP->WriteUvTcpFd(&hSession->hChildWorkTCP, bufPtr, bufLen); in SendByProtocol()
770 if (hSession->hWorkThread == uv_thread_self()) { in SendByProtocol()
771 ret = pTCP->WriteUvTcpFd(&hSession->hWorkTCP, bufPtr, bufLen); in SendByProtocol()
773 ret = pTCP->WriteUvTcpFd(&hSession->hChildWorkTCP, bufPtr, bufLen); in SendByProtocol()
779 HdcUSBBase *pUSB = ((HdcUSBBase *)hSession->classModule); in SendByProtocol()
780 ret = pUSB->SendUSBBlock(hSession, bufPtr, bufLen); in SendByProtocol()
786 HdcUARTBase *pUART = ((HdcUARTBase *)hSession->classModule); in SendByProtocol()
787 ret = pUART->SendUARTData(hSession, bufPtr, bufLen); in SendByProtocol()
802 HSession hSession = AdminSession(OP_QUERY, sessionId, nullptr); in Send() local
803 if (!hSession) { in Send()
851 return SendByProtocol(hSession, finayBuf, finalBufSize, true); in Send()
853 return SendByProtocol(hSession, finayBuf, finalBufSize); in Send()
857 int HdcSessionBase::DecryptPayload(HSession hSession, PayloadHead *payloadHeadBe, uint8_t *encBuf) in DecryptPayload() argument
874 if (!FetchCommand(hSession, protectBuf.channelId, protectBuf.commandFlag, data, dataSize)) { in DecryptPayload()
882 int HdcSessionBase::OnRead(HSession hSession, uint8_t *bufPtr, const int bufLen) in OnRead() argument
905 if (DecryptPayload(hSession, payloadHead, bufPtr + packetHeadSize)) { in OnRead()
914 int HdcSessionBase::FetchIOBuf(HSession hSession, uint8_t *ioBuf, int read) in FetchIOBuf() argument
916 HdcSessionBase *ptrConnect = (HdcSessionBase *)hSession->classInstance; in FetchIOBuf()
927 hSession->availTailIndex += read; in FetchIOBuf()
928 while (!hSession->isDead && hSession->availTailIndex > static_cast<int>(sizeof(PayloadHead))) { in FetchIOBuf()
929 childRet = ptrConnect->OnRead(hSession, ioBuf + indexBuf, hSession->availTailIndex); in FetchIOBuf()
931 hSession->availTailIndex -= childRet; in FetchIOBuf()
937 hSession->availTailIndex = 0; // Preventing malicious data packages in FetchIOBuf()
943 if (indexBuf > 0 && hSession->availTailIndex > 0) { in FetchIOBuf()
944 …if (memmove_s(hSession->ioBuf, hSession->bufSize, hSession->ioBuf + indexBuf, hSession->availTailI… in FetchIOBuf()
948 … uint8_t *bufToZero = reinterpret_cast<uint8_t *>(hSession->ioBuf + hSession->availTailIndex); in FetchIOBuf()
949 Base::ZeroBuf(bufToZero, hSession->bufSize - hSession->availTailIndex); in FetchIOBuf()
965 HSession hSession = (HSession)req->handle->data; in FinishWriteSessionTCP() local
966 --hSession->ref; in FinishWriteSessionTCP()
967 HdcSessionBase *thisClass = (HdcSessionBase *)hSession->classInstance; in FinishWriteSessionTCP()
970 if (!hSession->isDead && !hSession->ref) { in FinishWriteSessionTCP()
971 WRITE_LOG(LOG_DEBUG, "FinishWriteSessionTCP freesession :%u", hSession->sessionId); in FinishWriteSessionTCP()
972 thisClass->FreeSession(hSession->sessionId); in FinishWriteSessionTCP()
979 bool HdcSessionBase::DispatchSessionThreadCommand(HSession hSession, const uint8_t *baseBuf, in DispatchSessionThreadCommand() argument
999 HSession hSession = (HSession)poll->data; in ReadCtrlFromSession() local
1000 HdcSessionBase *hSessionBase = (HdcSessionBase *)hSession->classInstance; in ReadCtrlFromSession()
1003 ssize_t nread = Base::ReadFromFd(hSession->ctrlFd[STREAM_WORK], buf, size); in ReadCtrlFromSession()
1019 … hSessionBase->DispatchSessionThreadCommand(hSession, reinterpret_cast<uint8_t *>(buf), nread); in ReadCtrlFromSession()
1025 bool HdcSessionBase::WorkThreadStartSession(HSession hSession) in WorkThreadStartSession() argument
1029 if (hSession->connType == CONN_TCP) { in WorkThreadStartSession()
1030 HdcTCPBase *pTCPBase = (HdcTCPBase *)hSession->classModule; in WorkThreadStartSession()
1031 hSession->hChildWorkTCP.data = hSession; in WorkThreadStartSession()
1032 if (uv_tcp_init(&hSession->childLoop, &hSession->hChildWorkTCP) < 0) { in WorkThreadStartSession()
1036 if ((childRet = uv_tcp_open(&hSession->hChildWorkTCP, hSession->fdChildWorkTCP)) < 0) { in WorkThreadStartSession()
1040 … WRITE_LOG(LOG_DEBUG, "SessionCtrl failed 2,fd:%d,str:%s", hSession->fdChildWorkTCP, buf); in WorkThreadStartSession()
1043 Base::SetTcpOptions((uv_tcp_t *)&hSession->hChildWorkTCP); in WorkThreadStartSession()
1044 uv_read_start((uv_stream_t *)&hSession->hChildWorkTCP, AllocCallback, pTCPBase->ReadStream); in WorkThreadStartSession()
1047 } else if (hSession->connType == CONN_SERIAL) { // UART in WorkThreadStartSession()
1048 HdcUARTBase *pUARTBase = (HdcUARTBase *)hSession->classModule; in WorkThreadStartSession()
1050 regOK = pUARTBase->ReadyForWorkThread(hSession); in WorkThreadStartSession()
1053 HdcUSBBase *pUSBBase = (HdcUSBBase *)hSession->classModule; in WorkThreadStartSession()
1055 regOK = pUSBBase->ReadyForWorkThread(hSession); in WorkThreadStartSession()
1058 if (regOK && hSession->serverOrDaemon) { in WorkThreadStartSession()
1062 handshake.sessionId = hSession->sessionId; in WorkThreadStartSession()
1063 handshake.connectKey = hSession->connectKey; in WorkThreadStartSession()
1064 if (!hSession->isCheck) { in WorkThreadStartSession()
1072 hSession->sessionId, handshake.authType, hs.c_str()); in WorkThreadStartSession()
1074 Send(hSession->sessionId, 0, CMD_KERNEL_HANDSHAKE, in WorkThreadStartSession()
1102 bool HdcSessionBase::DispatchMainThreadCommand(HSession hSession, const CtrlStruct *ctrl) in DispatchMainThreadCommand() argument
1109 hSession->sessionId, hSession->serverOrDaemon ? "server" : "daemon"); in DispatchMainThreadCommand()
1110 ret = WorkThreadStartSession(hSession); in DispatchMainThreadCommand()
1114 … WRITE_LOG(LOG_DEBUG, "Dispatch MainThreadCommand STOP_SESSION sessionId:%u", hSession->sessionId); in DispatchMainThreadCommand()
1116 HSession hSession = (HSession)handle->data; in DispatchMainThreadCommand() local
1118 if (handle == (uv_handle_t *)hSession->pollHandle[STREAM_WORK]) { in DispatchMainThreadCommand()
1119 free(hSession->pollHandle[STREAM_WORK]); in DispatchMainThreadCommand()
1121 if (--hSession->uvChildRef == 0) { in DispatchMainThreadCommand()
1122 uv_stop(&hSession->childLoop); in DispatchMainThreadCommand()
1125 hSession->uvChildRef += 2; in DispatchMainThreadCommand()
1126 … if (hSession->connType == CONN_TCP && hSession->hChildWorkTCP.loop) { // maybe not use it in DispatchMainThreadCommand()
1127 ++hSession->uvChildRef; in DispatchMainThreadCommand()
1128 …Base::TryCloseHandle((uv_handle_t *)&hSession->hChildWorkTCP, true, closeSessionChildThreadTCPHand… in DispatchMainThreadCommand()
1130 Base::TryCloseHandle((uv_handle_t *)hSession->pollHandle[STREAM_WORK], true, in DispatchMainThreadCommand()
1132 Base::TryCloseHandle((uv_handle_t *)&hSession->dataPipe[STREAM_WORK], true, in DispatchMainThreadCommand()
1140 AttachChannel(hSession, channelId); in DispatchMainThreadCommand()
1147 DeatchChannel(hSession, channelId); in DispatchMainThreadCommand()
1161 HSession hSession = (HSession)poll->data; in ReadCtrlFromMain() local
1162 HdcSessionBase *hSessionBase = (HdcSessionBase *)hSession->classInstance; in ReadCtrlFromMain()
1167 ssize_t nread = Base::ReadFromFd(hSession->ctrlFd[STREAM_WORK], buf, size); in ReadCtrlFromMain()
1181 if (!hSessionBase->DispatchMainThreadCommand(hSession, ctrl)) { in ReadCtrlFromMain()
1183 hSession->sessionId, ctrl->channelId, ctrl->command); in ReadCtrlFromMain()
1194 void HdcSessionBase::ReChildLoopForSessionClear(HSession hSession) in ReChildLoopForSessionClear() argument
1197 ClearOwnTasks(hSession, 0); in ReChildLoopForSessionClear()
1198 WRITE_LOG(LOG_INFO, "ReChildLoopForSessionClear sessionId:%u", hSession->sessionId); in ReChildLoopForSessionClear()
1200 HSession hSession = (HSession)handle->data; in ReChildLoopForSessionClear() local
1201 for (auto v : *hSession->mapTask) { in ReChildLoopForSessionClear()
1213 hSession = thisClass->AdminSession(OP_QUERY, hTask->sessionId, nullptr); in ReChildLoopForSessionClear()
1214 thisClass->AdminTask(OP_VOTE_RESET, hSession, hTask->channelId, nullptr); in ReChildLoopForSessionClear()
1221 uv_stop(&hSession->childLoop); // stop ReChildLoopForSessionClear pendding in ReChildLoopForSessionClear()
1223 …Base::TimerUvTask(&hSession->childLoop, hSession, clearTaskForSessionFinish, (GLOBAL_TIMEOUT * TIM… in ReChildLoopForSessionClear()
1224 uv_run(&hSession->childLoop, UV_RUN_DEFAULT); in ReChildLoopForSessionClear()
1226 Base::TryCloseLoop(&hSession->childLoop, "Session childUV"); in ReChildLoopForSessionClear()
1231 HSession hSession = (HSession)arg->data; in SessionWorkThread() local
1232 HdcSessionBase *thisClass = (HdcSessionBase *)hSession->classInstance; in SessionWorkThread()
1233 hSession->hWorkChildThread = uv_thread_self(); in SessionWorkThread()
1235 uv_poll_t *pollHandle = hSession->pollHandle[STREAM_WORK]; in SessionWorkThread()
1236 pollHandle->data = hSession; in SessionWorkThread()
1237 uv_poll_init_socket(&hSession->childLoop, pollHandle, hSession->ctrlFd[STREAM_WORK]); in SessionWorkThread()
1239 WRITE_LOG(LOG_DEBUG, "!!!Workthread run begin, sessionId:%u instance:%s", hSession->sessionId, in SessionWorkThread()
1241 uv_run(&hSession->childLoop, UV_RUN_DEFAULT); // work pendding in SessionWorkThread()
1242 WRITE_LOG(LOG_DEBUG, "!!!Workthread run again, sessionId:%u", hSession->sessionId); in SessionWorkThread()
1244 thisClass->ReChildLoopForSessionClear(hSession); // work pending again in SessionWorkThread()
1245 hSession->childCleared = true; in SessionWorkThread()
1246 WRITE_LOG(LOG_DEBUG, "!!!Workthread run finish, sessionId:%u", hSession->sessionId); in SessionWorkThread()
1303 bool HdcSessionBase::DispatchTaskData(HSession hSession, const uint32_t channelId, const uint16_t c… in DispatchTaskData() argument
1320 hTaskInfo->sessionId = hSession->sessionId; in DispatchTaskData()
1321 hTaskInfo->runLoop = &hSession->childLoop; in DispatchTaskData()
1329 if (AdminTask(OP_ADD, hSession, channelId, hTaskInfo)) { in DispatchTaskData()
1346 hTaskInfo = AdminTask(OP_QUERY, hSession, channelId, nullptr); in DispatchTaskData()
1352 ret = RedirectToTask(hTaskInfo, hSession, channelId, command, payload, payloadSize); in DispatchTaskData()