diff --git a/base/src/event_demultiplexer.cpp b/base/src/event_demultiplexer.cpp index d35b8115b3ab9ee9cb2e86a0fcba1791a413180e..34c109e79088f518e917160631feda7904730425 100644 --- a/base/src/event_demultiplexer.cpp +++ b/base/src/event_demultiplexer.cpp @@ -31,9 +31,11 @@ static const int EPOLL_INVALID_FD = -1; static const int INTERRUPTED_SYS_CALL = 4; static const int EPOLL_ERROR_BADF = 9; static const int EPOLL_ERROR_EINVAL = 22; +static const int QUEUE_MAX_SIZE = 10; EventDemultiplexer::EventDemultiplexer() - : epollFd_(epoll_create1(EPOLL_CLOEXEC)), maxEvents_(EPOLL_MAX_EVENS_INIT), mutex_(), eventHandlers_() + : epollFd_(epoll_create1(EPOLL_CLOEXEC)), maxEvents_(EPOLL_MAX_EVENS_INIT), mutex_(), eventHandlers_(), + epollCtlErrQueue_() { } @@ -93,8 +95,12 @@ uint32_t EventDemultiplexer::Update(int operation, EventHandler* handler) event.data.fd = handler->GetHandle(); if (epoll_ctl(epollFd_, operation, handler->GetHandle(), &event) != 0) { - UTILS_LOGD("epoll_ctl %{public}d operation %{public}d on handle %{public}d failed", - epollFd_, operation, handler->GetHandle()); + UTILS_LOGE("epoll_ctl %{public}d operation %{public}d on handle %{public}d failed, errno %{public}d", + epollFd_, operation, handler->GetHandle(), errno); + + if (epollCtlErrQueue_.size() < QUEUE_MAX_SIZE) { + epollCtlErrQueue_.push(std::make_tuple(operation, errno, handler->GetHandle())); + } return TIMER_ERR_DEAL_FAILED; } return TIMER_ERR_OK; @@ -134,6 +140,12 @@ int EventDemultiplexer::Polling(int timeout /* ms */) eventQue.emplace_back(events); } else { UTILS_LOGE("fd not found in eventHandlers_, fd=%{public}d, events=%{public}d", targetFd, events); + + while (!epollCtlErrQueue_.empty()) { + auto [operation, errnoNum, fd] = epollCtlErrQueue_.front(); + UTILS_LOGE("epoll_ctl: %{public}d, errno: %{public}d, handle: %{public}d", operation, errnoNum, fd); + epollCtlErrQueue_.pop(); + } } } } diff --git a/base/src/event_demultiplexer.h b/base/src/event_demultiplexer.h index 75a3d7b0fa56bcc0fabe8914d317e892bfa389be..02b2d9a6a31a6e2af335635977486a66a87171f4 100644 --- a/base/src/event_demultiplexer.h +++ b/base/src/event_demultiplexer.h @@ -20,6 +20,8 @@ #include #include #include +#include +#include namespace OHOS { namespace Utils { @@ -49,6 +51,7 @@ private: int maxEvents_; std::recursive_mutex mutex_; std::map> eventHandlers_; // guard by mutex_ + std::queue> epollCtlErrQueue_; }; }