From b0282fe36fc18682111d40ab9f22e8d2dcd293bd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 9 Oct 2020 17:50:34 +0200 Subject: [PATCH] event/PollGroupWinSelect: add Item constructor --- src/event/WinSelectBackend.cxx | 9 +++------ src/event/WinSelectBackend.hxx | 10 ++++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/event/WinSelectBackend.cxx b/src/event/WinSelectBackend.cxx index 76a9dfd7a..a0a05bc99 100644 --- a/src/event/WinSelectBackend.cxx +++ b/src/event/WinSelectBackend.cxx @@ -64,14 +64,11 @@ bool WinSelectBackend::Add(SOCKET fd, unsigned events, void *obj) noexcept { assert(items.find(fd) == items.end()); - auto i = items.emplace(fd, Item{}).first; + auto i = items.emplace(std::piecewise_construct, + std::forward_as_tuple(fd), + std::forward_as_tuple(obj)).first; auto &item = i->second; - item.index[EVENT_READ] = -1; - item.index[EVENT_WRITE] = -1; - item.obj = obj; - item.events = 0; - if (!CanModify(item, events, EVENT_READ)) { items.erase(i); return false; diff --git a/src/event/WinSelectBackend.hxx b/src/event/WinSelectBackend.hxx index 50cdd75d5..94fbbd353 100644 --- a/src/event/WinSelectBackend.hxx +++ b/src/event/WinSelectBackend.hxx @@ -91,9 +91,15 @@ class WinSelectBackend { struct Item { - int index[2]; + int index[2]{-1, -1}; void *obj; - unsigned events; + unsigned events = 0; + + explicit constexpr Item(void *_obj) noexcept + :obj(_obj) {} + + Item(const Item &) = delete; + Item &operator=(const Item &) = delete; }; SocketSet event_set[2];