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];