MCPcopy Create free account
hub / github.com/F-Stack/f-stack / InitConnEnv

Method InitConnEnv

adapter/micro_thread/mt_action.cpp:65–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63};
64
65int IMtAction::InitConnEnv()
66{
67 MtFrame* mtframe = MtFrame::Instance();
68 ConnectionMgr* connmgr = ConnectionMgr::Instance();
69 MsgBuffPool* msgmgr = MsgBuffPool::Instance();
70 NtfyObjMgr* ntfymgr = NtfyObjMgr::Instance();
71 SessionMgr* sessionmgr = SessionMgr::Instance();
72
73 if (_conn != NULL) {
74 MTLOG_ERROR("Action init failed, maybe action reused in actionlist, check it!!");
75 return -100;
76 }
77
78 CONN_OBJ_TYPE conn_obj_type = OBJ_CONN_UNDEF;
79 NTFY_OBJ_TYPE ntfy_obj_type = NTFY_OBJ_UNDEF;
80
81 MULTI_PROTO proto = this->GetProtoType();
82 MULTI_CONNECT type = this->GetConnType();
83 if ((MT_UDP == proto) && (CONN_TYPE_SESSION == type)) // UDP session
84 {
85 conn_obj_type = OBJ_UDP_SESSION;
86 ntfy_obj_type = NTFY_OBJ_SESSION;
87 }
88 else if (MT_UDP == proto) // UDP
89 {
90 conn_obj_type = OBJ_SHORT_CONN;
91 ntfy_obj_type = NTFY_OBJ_THREAD;
92 }
93 else // TCP
94 {
95 conn_obj_type = OBJ_TCP_KEEP;
96 ntfy_obj_type = NTFY_OBJ_THREAD;
97 }
98
99 _conn = connmgr->GetConnection(conn_obj_type, this->GetMsgDstAddr());
100 if (!_conn) {
101 MTLOG_ERROR("Get conn failed, type: %d", conn_obj_type);
102 return -1;
103 }
104 _conn->SetIMtActon(this);
105
106 int max_len = this->GetMsgBuffSize();
107 MtMsgBuf* msg_buff = msgmgr->GetMsgBuf(max_len);
108 if (!msg_buff) {
109 MTLOG_ERROR("Maybe no memory, buffsize: %d, get failed", max_len);
110 return -2;
111 }
112 msg_buff->SetBuffType(BUFF_SEND);
113 _conn->SetMtMsgBuff(msg_buff);
114
115 KqueuerObj* ntfy_obj = ntfymgr->GetNtfyObj(ntfy_obj_type, _ntfy_name);
116 if (!ntfy_obj) {
117 MTLOG_ERROR("Maybe no memory, ntfy type: %d, get failed", ntfy_obj_type);
118 return -3;
119 }
120 _conn->SetNtfyObj(ntfy_obj);
121
122 MicroThread* thread = mtframe->GetActiveThread();

Callers 1

mt_msg_sendrcvMethod · 0.80

Calls 15

GetProtoTypeMethod · 0.95
GetConnTypeMethod · 0.95
GetMsgDstAddrMethod · 0.95
GetMsgBuffSizeMethod · 0.95
SetIMsgPtrMethod · 0.95
GetConnectionMethod · 0.80
SetIMtActonMethod · 0.80
SetBuffTypeMethod · 0.80
SetMtMsgBuffMethod · 0.80
SetNtfyObjMethod · 0.80
GetActiveThreadMethod · 0.80
GetThreadArgsMethod · 0.80

Tested by

no test coverage detected