From 9e97acc28dd6cc05c94ad9f9477a8596069658db Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 30 Oct 2020 15:55:22 +0100 Subject: [PATCH] event/WinSelect: merge duplicate code into ApplyReady() --- src/event/WinSelectBackend.cxx | 19 +++++++++++-------- src/event/WinSelectBackend.hxx | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/event/WinSelectBackend.cxx b/src/event/WinSelectBackend.cxx index 4e919a85e..0db4c0a1c 100644 --- a/src/event/WinSelectBackend.cxx +++ b/src/event/WinSelectBackend.cxx @@ -117,6 +117,14 @@ WinSelectBackend::Remove(SOCKET fd) noexcept return true; } +void +WinSelectBackend::ApplyReady(const SocketSet &src, unsigned events) noexcept +{ + for (const auto i : src) { + items[i].events |= events; + } +} + PollResultGeneric WinSelectBackend::ReadEvents(int timeout_ms) noexcept { @@ -148,14 +156,9 @@ WinSelectBackend::ReadEvents(int timeout_ms) noexcept if (ret == 0 || ret == SOCKET_ERROR) return result; - for (const auto i : read_set) - items[i].events |= WinSelectEvents::READ; - - for (const auto i : write_set) - items[i].events |= WinSelectEvents::WRITE; - - for (const auto i : except_set) - items[i].events |= WinSelectEvents::WRITE; + ApplyReady(read_set, WinSelectEvents::READ); + ApplyReady(write_set, WinSelectEvents::WRITE); + ApplyReady(except_set, WinSelectEvents::WRITE); for (auto &i : items) if (i.second.events != 0) { diff --git a/src/event/WinSelectBackend.hxx b/src/event/WinSelectBackend.hxx index 03a607890..50cdd75d5 100644 --- a/src/event/WinSelectBackend.hxx +++ b/src/event/WinSelectBackend.hxx @@ -119,6 +119,8 @@ private: int event_id) const noexcept; void Modify(Item &item, SOCKET fd, unsigned events, int event_id) noexcept; + + void ApplyReady(const SocketSet &src, unsigned events) noexcept; }; #endif