handy icon indicating copy to clipboard operation
handy copied to clipboard

loop 问题

Open guanweile opened this issue 3 years ago • 5 comments

你好 问一个问题 void EventsImp::loop() { while (!exit_) loop_once(10000); timerReps_.clear(); timers_.clear(); idleConns_.clear(); for (auto recon : reconnectConns_) { //重连的连接无法通过channel清理,因此单独清理 recon->cleanup(recon); } loop_once(0); }

为什么要 while (!exit_) loop_once(10000); 和 loop_once(0);

guanweile avatar Sep 07 '22 13:09 guanweile

handy支持优雅退出,方便使用工具检查内存泄漏问题 如果在某个地方调用了EventBase.exit,那么exit_会标记为true 后面还有一个loop_once是用于部分资源清理

yedf2 avatar Sep 08 '22 09:09 yedf2

loop_once(0); 这个是epoll_wait 的超时时间为0 超时时间等于零导致epoll_wait 立即返回,即使没有可用事件 这个是用于干嘛? 清理资源?

guanweile avatar Sep 08 '22 12:09 guanweile

还有 一个疑问就是 loop 的时候 loop_once(10000); 没退出的时候 epoll_wait 没事件 会阻塞下面的clear() 直到 有事件到 才会clear 这样为什么要等有事件 才clear..

guanweile avatar Sep 08 '22 12:09 guanweile

@yedf2

guanweile avatar Sep 20 '22 04:09 guanweile

loop_once(0)会进行连接的IO处理,因为前面的处理中,可能会关闭了一部分连接,因此需要loop_once进行清理 timer这些clear本来10秒清理一次就够,所以没有必要特别频繁的去调用他

yedf2 avatar Sep 20 '22 14:09 yedf2