MCPcopy Create free account
hub / github.com/caozhiyi/CppNet / ProcessEvent

Method ProcessEvent

net/linux/CEpoll.cpp:246–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244}
245
246void CEpoll::ProcessEvent() {
247 uint32_t wait_time = 0;
248 std::vector<base::CMemSharePtr<CTimerEvent>> timer_vec;;
249 std::vector<epoll_event> event_vec;
250 event_vec.resize(1000);
251 while (_run) {
252 wait_time = _timer.TimeoutCheck(timer_vec);
253 //if there is no timer event. wait until recv something
254 if (wait_time == 0 && timer_vec.empty()) {
255 wait_time = -1;
256 } else {
257 wait_time = wait_time > 0 ? wait_time : 1;
258 }
259 int res = epoll_wait(_epoll_handler, &*event_vec.begin(), (int)(event_vec.size()), wait_time);
260 if (res == -1) {
261 base::LOG_ERROR("epoll_wait faild! error :%d", errno);
262 }
263
264 if (res > 0) {
265 base::LOG_DEBUG("epoll_wait get events! num :%d, TheadId : %lld", res, std::this_thread::get_id());
266
267 _DoEvent(event_vec, res);
268 _DoTaskList();
269 if (!timer_vec.empty()) {
270 _DoTimeoutEvent(timer_vec);
271 }
272
273 } else {
274 if (!timer_vec.empty()) {
275 _DoTimeoutEvent(timer_vec);
276 }
277 _DoTaskList();
278 }
279 }
280
281 if (close(_epoll_handler) == -1) {
282 base::LOG_ERROR("epoll close failed! error : %d", errno);
283 }
284 if (close(_pipe[0]) == -1) {
285 base::LOG_ERROR("_pipe[0] close failed! error : %d", errno);
286 }
287 if (close(_pipe[1]) == -1) {
288 base::LOG_ERROR("_pipe[1] close failed! error : %d", errno);
289 }
290 base::LOG_INFO("return the net io thread");
291}
292
293void CEpoll::PostTask(std::function<void(void)>& task) {
294 {

Callers

nothing calls this directly

Calls 1

TimeoutCheckMethod · 0.80

Tested by

no test coverage detected