void stGateTask::RemoveFromManager() { Global::logger->debug("task terminate <userid=%llu,taskid=%llu>", GetUserId(), GetTaskId()); stGateUser * p_user = stGateUserManager::GetInstance().GetUser(GetUserId()); if(p_user) { p_user->DisConnect(GetTaskId(), stGateTick::m_stRTime.GetMSec()); } else { Global::logger->debug("why not find user <%llu>", GetUserId()); stAssert(0); } stGateTaskManager::GetInstance().RemoveTask(this); }
void CTestTask::taskProc() { for (int i = 1; i < 100000;i++) { std::cout << "Thread id=" << GetTaskId() << "х┌"<<i<<"┤╬н╦лл" << std::endl; Sleep(timeMs); } }
BOOL CUploadDirRecusion::Run() { CTaskBase *pTask = thePoolManager.GetTaskFromHistory(GetTaskId()); CUploadDirRecusion * pUploadTaskHistory = NULL; if (pTask && pTask->m_strOperation=="uploadDir") pUploadTaskHistory = dynamic_cast<CUploadDirRecusion*>(pTask); ASSERT(pUploadTaskHistory!=NULL); if (!m_bFlag) { pUploadTaskHistory->SetTaskStatus(CTaskBase::task_error); return FALSE; } BOOL bok = FALSE; pUploadTaskHistory->SetTaskStatus(CTaskBase::task_running); bok = UploadDirRecusion(m_strLocalDir,m_strNetDiskDir); pUploadTaskHistory->SetTaskStatus(CTaskBase::task_finish); return bok; }
bool stGateTask::CmdParse(const Cmd::stNullCmd * pt_null_cmd, const int cmd_size) { if((unsigned int)cmd_size < sizeof(Cmd::stProtoBufCmd)) { Global::logger->fatal("[gate_cmd_error] this user send cmd len less sizeof(stprotobufcmd) <ip=%s,port=%u>", GetIP(),GetPort()); Terminate(); stAssert(0); return false; } const Cmd::stProtoBufCmd * p_recv_cmd = (const Cmd::stProtoBufCmd *)pt_null_cmd; DWORD cmd_id = p_recv_cmd->cmdid; defCheckCmdLen(cmd_id, p_recv_cmd->cmdlen, (defCmdId)cmd_size); if(!is_check) { Global::logger->fatal("[gate_cmd_error] this user send cmd length error <ip=%s,port=%u,cmdid=%u,cmdsize=%u>", GetIP(),GetPort(), cmd_id, cmd_size); Terminate(); stAssert(0); return false; } Global::logger->debug("[gate_cmd] recv a command <ip=%s,port=%u,id=%u,len=%u>",GetIP(), GetPort(), cmd_id,cmd_size); if(IsInit()) { stGateUser * p_user = stGateUserManager::GetInstance().GetUser(userid); if(!p_user) { Terminate(); return true; } SendCmdToInfo(pt_null_cmd, cmd_size); } else { /// 登录 if(cmd_id == Cmd::enRequestLogin) { Cmd::cmdRequestLogin p_recv; p_recv.google::protobuf::MessageLite::ParseFromArray(p_recv_cmd->data, p_recv_cmd->cmdlen); Global::logger->debug("[login_cmd] recv login para <token=%s,uniqueid=%s>", p_recv.token().c_str(), p_recv.uniqueid().c_str()); Cmd::cmdRegisterUser info_cmd; info_cmd.set_isrec(false); if(p_recv.has_tempid()) { stGateUser * p_old_user = stGateUserManager::GetInstance().GetUser(p_recv.tempid()); if(p_old_user) { SetInit(p_recv.tempid()); p_old_user->Connect(); p_old_user->SetTask(this); info_cmd.set_isrec(true); info_cmd.set_tempid(p_old_user->GetTempId()); info_cmd.set_uniqueid(p_old_user->GetUniqueId()); SendCmdToInfo(Cmd::enRegisterUser, &info_cmd, info_cmd.ByteSize()); Global::logger->debug("reconnect <tempid=%llu>", p_recv.tempid()); Cmd::cmdNotifyLoginResult send_cmd; send_cmd.set_result(Cmd::cmdNotifyLoginResult::LOGIN_RESULT_OK); send_cmd.set_tempid(p_recv.tempid()); SendCmd(Cmd::enNotifyLoginResult, &send_cmd, send_cmd.ByteSize()); return true; } } stGateUser * p_new_user = new stGateUser(GetTaskId(), p_recv.uniqueid().c_str()); p_new_user->SetTask(this); stGateUserManager::GetInstance().AddUser(p_new_user); Cmd::cmdNotifyLoginResult send_cmd; send_cmd.set_result(Cmd::cmdNotifyLoginResult::LOGIN_RESULT_OK); send_cmd.set_tempid(GetTaskId()); SendCmd(Cmd::enNotifyLoginResult, &send_cmd, send_cmd.ByteSize()); SetInit(GetTaskId()); info_cmd.set_tempid(GetTaskId()); info_cmd.set_uniqueid(p_recv.uniqueid()); SendCmdToInfo(Cmd::enRegisterUser, &info_cmd, info_cmd.ByteSize()); } else { Global::logger->debug("recv error cmd <%u>", cmd_id); stAssert(0); Terminate(); } } return true; }