diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 3a6b7654a..80507aa5d 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -257,8 +257,8 @@ EventLoop::Run() noexcept /* wait for new event */ - PollResult poll_result; - poll_group.ReadEvents(poll_result, ExportTimeoutMS(timeout)); + const auto poll_result = + poll_group.ReadEvents(ExportTimeoutMS(timeout)); ready_sockets.clear(); for (size_t i = 0; i < poll_result.GetSize(); ++i) { diff --git a/src/event/PollGroup.hxx b/src/event/PollGroup.hxx index a38c63f1b..104f1619d 100644 --- a/src/event/PollGroup.hxx +++ b/src/event/PollGroup.hxx @@ -25,19 +25,16 @@ #ifdef _WIN32 #include "PollGroupWinSelect.hxx" -typedef PollResultGeneric PollResult; typedef PollGroupWinSelect PollGroup; #elif defined(USE_EPOLL) #include "PollGroupEpoll.hxx" -typedef PollResultEpoll PollResult; typedef PollGroupEpoll PollGroup; #else #include "PollGroupPoll.hxx" -typedef PollResultGeneric PollResult; typedef PollGroupPoll PollGroup; #endif diff --git a/src/event/PollGroupEpoll.hxx b/src/event/PollGroupEpoll.hxx index 16035a28a..35fa504f4 100644 --- a/src/event/PollGroupEpoll.hxx +++ b/src/event/PollGroupEpoll.hxx @@ -61,10 +61,12 @@ public: PollGroupEpoll() = default; - void ReadEvents(PollResultEpoll &result, int timeout_ms) noexcept { + auto ReadEvents(int timeout_ms) noexcept { + PollResultEpoll result; int ret = epoll.Wait(result.events.data(), result.events.size(), timeout_ms); result.n_events = std::max(0, ret); + return result; } bool Add(int fd, unsigned events, void *obj) noexcept { diff --git a/src/event/PollGroupPoll.cxx b/src/event/PollGroupPoll.cxx index 47951a131..a81b2ab2f 100644 --- a/src/event/PollGroupPoll.cxx +++ b/src/event/PollGroupPoll.cxx @@ -71,12 +71,13 @@ PollGroupPoll::Remove(int fd) noexcept return true; } -void -PollGroupPoll::ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept +PollResultGeneric +PollGroupPoll::ReadEvents(int timeout_ms) noexcept { int n = poll(poll_events.empty() ? nullptr : &poll_events[0], poll_events.size(), timeout_ms); + PollResultGeneric result; for (size_t i = 0; n > 0 && i < poll_events.size(); ++i) { const auto &e = poll_events[i]; if (e.revents != 0) { @@ -84,4 +85,6 @@ PollGroupPoll::ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept --n; } } + + return result; } diff --git a/src/event/PollGroupPoll.hxx b/src/event/PollGroupPoll.hxx index be14fc71b..19987778c 100644 --- a/src/event/PollGroupPoll.hxx +++ b/src/event/PollGroupPoll.hxx @@ -50,7 +50,7 @@ public: PollGroupPoll() noexcept; ~PollGroupPoll() noexcept; - void ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept; + PollResultGeneric ReadEvents(int timeout_ms) noexcept; bool Add(int fd, unsigned events, void *obj) noexcept; bool Modify(int fd, unsigned events, void *obj) noexcept; bool Remove(int fd) noexcept; diff --git a/src/event/PollGroupWinSelect.cxx b/src/event/PollGroupWinSelect.cxx index 29a6f5e0a..ed0c2b7eb 100644 --- a/src/event/PollGroupWinSelect.cxx +++ b/src/event/PollGroupWinSelect.cxx @@ -115,9 +115,8 @@ PollGroupWinSelect::Remove(SOCKET fd) noexcept return true; } -void -PollGroupWinSelect::ReadEvents(PollResultGeneric &result, - int timeout_ms) noexcept +PollResultGeneric +PollGroupWinSelect::ReadEvents(int timeout_ms) noexcept { bool use_sleep = event_set[EVENT_READ].IsEmpty() && event_set[EVENT_WRITE].IsEmpty(); @@ -143,8 +142,9 @@ PollGroupWinSelect::ReadEvents(PollResultGeneric &result, except_set.GetPtr(), timeout_ms < 0 ? nullptr : &tv); + PollResultGeneric result; if (ret == 0 || ret == SOCKET_ERROR) - return; + return result; for (const auto i : read_set) items[i].events |= READ; @@ -160,4 +160,6 @@ PollGroupWinSelect::ReadEvents(PollResultGeneric &result, result.Add(i.second.events, i.second.obj); i.second.events = 0; } + + return result; } diff --git a/src/event/PollGroupWinSelect.hxx b/src/event/PollGroupWinSelect.hxx index fb927897f..a3a7b2174 100644 --- a/src/event/PollGroupWinSelect.hxx +++ b/src/event/PollGroupWinSelect.hxx @@ -122,7 +122,7 @@ public: PollGroupWinSelect() noexcept; ~PollGroupWinSelect() noexcept; - void ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept; + PollResultGeneric ReadEvents(int timeout_ms) noexcept; bool Add(SOCKET fd, unsigned events, void *obj) noexcept; bool Modify(SOCKET fd, unsigned events, void *obj) noexcept; bool Remove(SOCKET fd) noexcept;