Skip to content

Commit

Permalink
Fix the EventPoller exit exception. (ZLMediakit #3789)
Browse files Browse the repository at this point in the history
  • Loading branch information
PioLing committed Aug 6, 2024
1 parent abf61ef commit 80456b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions src/Poller/EventPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ EventPoller::~EventPoller() {
#endif

//退出前清理管道中的数据
onPipeEvent();
onPipeEvent(true);
InfoL << getThreadName();
}

Expand Down Expand Up @@ -276,23 +276,25 @@ bool EventPoller::isCurrentThread() {
return !_loop_thread || _loop_thread->get_id() == this_thread::get_id();
}

inline void EventPoller::onPipeEvent() {
inline void EventPoller::onPipeEvent(bool flus) {
char buf[1024];
int err = 0;
while (true) {
if ((err = _pipe.read(buf, sizeof(buf))) > 0) {
// 读到管道数据,继续读,直到读空为止
continue;
}
if (err == 0 || get_uv_error(true) != UV_EAGAIN) {
// 收到eof或非EAGAIN(无更多数据)错误,说明管道无效了,重新打开管道
ErrorL << "Invalid pipe fd of event poller, reopen it";
delEvent(_pipe.readFD());
_pipe.reOpen();
addEventPipe();
}
break;
}
if (!flus) {
for (;;) {
if ((err = _pipe.read(buf, sizeof(buf))) > 0) {
// 读到管道数据,继续读,直到读空为止
continue;
}
if (err == 0 || get_uv_error(true) != UV_EAGAIN) {
// 收到eof或非EAGAIN(无更多数据)错误,说明管道无效了,重新打开管道
ErrorL << "Invalid pipe fd of event poller, reopen it";
delEvent(_pipe.readFD());
_pipe.reOpen();
addEventPipe();
}
break;
}
}

decltype(_list_task) _list_swap;
{
Expand Down
2 changes: 1 addition & 1 deletion src/Poller/EventPoller.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class EventPoller : public TaskExecutor, public AnyStorage, public std::enable_s
/**
* 内部管道事件,用于唤醒轮询线程用
*/
void onPipeEvent();
void onPipeEvent(bool flus = false);

/**
* 切换线程并执行任务
Expand Down

0 comments on commit 80456b4

Please sign in to comment.