MCPcopy Create free account
hub / github.com/e2wugui/zeze / Update

Method Update

cxx/ToLua.cpp:122–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 void ToLua::Update(Service* service)
123 {
124 ToLuaHandshakeDoneMap handshakeTmp;
125 ToLuaSocketCloseMap socketCloseTmp;;
126 std::unordered_set<long long> rpcTimeoutTmp;
127 ToLuaBufferMap inputTmp;
128 {
129 std::lock_guard<std::mutex> lock(mutex);
130 handshakeTmp.swap(ToLuaHandshakeDone);
131 inputTmp.swap(ToLuaBuffer);
132 socketCloseTmp.swap(ToLuaSocketClose);
133 rpcTimeoutTmp.swap(ToLuaRpcTimeout);
134 }
135 for (auto& sid : rpcTimeoutTmp)
136 CallRpcTimeout(sid);
137 for (auto& e : socketCloseTmp)
138 CallSocketClose(e.second, e.first);
139 for (auto& e : handshakeTmp)
140 CallHandshakeDone(e.second, e.first);
141
142 for (auto& e : inputTmp)
143 {
144 std::shared_ptr<Socket> sender = service->GetSocket(e.first);
145 if (NULL == sender.get())
146 continue;
147 Zeze::ByteBuffer bb((unsigned char*)e.second.data(), 0, (int)e.second.size());
148 Protocol::DecodeProtocol(service, sender, bb, this);
149 e.second.erase(0, bb.ReadIndex);
150 }
151
152 {
153 std::lock_guard<std::mutex> lock(mutex);
154 for (auto& e : inputTmp)
155 {
156 if (e.second.empty())
157 continue; // 数据全部处理完成。
158
159 ToLuaBufferMap::iterator bit = ToLuaBuffer.find(e.first);
160 if (bit != ToLuaBuffer.end())
161 {
162 // 处理过程中有新数据到来,加到当前剩余数据后面,然后覆盖掉buffer。
163 e.second.append(bit->second);
164 ToLuaBuffer[e.first] = e.second;
165 }
166 else
167 {
168 // 没有新数据到来,有剩余,加回去。下一次update再处理。
169 ToLuaBuffer[e.first] = e.second;
170 }
171 }
172 }
173 }
174
175 void ToLua::RegisterGlobalAndCallback(ToLuaService* service)
176 {

Callers 1

ZezeUpdateMethod · 0.45

Calls 9

DecodeProtocolFunction · 0.85
getMethod · 0.65
sizeMethod · 0.65
findMethod · 0.65
swapMethod · 0.45
GetSocketMethod · 0.45
eraseMethod · 0.45
endMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected