diff --git a/src/event/MultiSocketMonitor.cxx b/src/event/MultiSocketMonitor.cxx index adb05980e..9bd23a10c 100644 --- a/src/event/MultiSocketMonitor.cxx +++ b/src/event/MultiSocketMonitor.cxx @@ -66,27 +66,26 @@ MultiSocketMonitor::ClearSocketList() noexcept #ifndef _WIN32 void -MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept +MultiSocketMonitor::ReplaceSocketList(std::span pfds) noexcept { #ifdef USE_EPOLL always_ready_fds.clear(); #endif - pollfd *const end = pfds + n; - - UpdateSocketList([pfds, end](SocketDescriptor fd) -> unsigned { - auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){ + UpdateSocketList([pfds](SocketDescriptor fd) -> unsigned { + auto i = std::find_if(pfds.begin(), pfds.end(), [fd](const struct pollfd &pfd){ return pfd.fd == fd.Get(); }); - if (i == end) + + if (i == pfds.end()) return 0; return std::exchange(i->events, 0); }); - for (auto i = pfds; i != end; ++i) - if (i->events != 0) - AddSocket(SocketDescriptor(i->fd), i->events); + for (const auto &i : pfds) + if (i.events != 0) + AddSocket(SocketDescriptor(i.fd), i.events); } #endif diff --git a/src/event/MultiSocketMonitor.hxx b/src/event/MultiSocketMonitor.hxx index c543388a2..68e4bd768 100644 --- a/src/event/MultiSocketMonitor.hxx +++ b/src/event/MultiSocketMonitor.hxx @@ -12,6 +12,7 @@ #include #include #include +#include #ifndef _WIN32 struct pollfd; @@ -190,7 +191,7 @@ public: * * May only be called from PrepareSockets(). */ - void ReplaceSocketList(pollfd *pfds, unsigned n) noexcept; + void ReplaceSocketList(std::span pfds) noexcept; #endif /** diff --git a/src/lib/alsa/NonBlock.cxx b/src/lib/alsa/NonBlock.cxx index f15ebeb2a..66f291cae 100644 --- a/src/lib/alsa/NonBlock.cxx +++ b/src/lib/alsa/NonBlock.cxx @@ -26,7 +26,7 @@ AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) throw Alsa::MakeError(count, "snd_pcm_poll_descriptors() failed"); } - m.ReplaceSocketList(pfds, count); + m.ReplaceSocketList({pfds, static_cast(count)}); return Event::Duration(-1); } @@ -71,7 +71,7 @@ AlsaNonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noe if (count < 0) count = 0; - m.ReplaceSocketList(pfds, count); + m.ReplaceSocketList({pfds, static_cast(count)}); return Event::Duration(-1); }