Skip to content

Commit

Permalink
event/MultiSocketMonitor: pass std::span to ReplaceSocketList()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 11, 2024
1 parent 45f92f0 commit 9aa6b03
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
17 changes: 8 additions & 9 deletions src/event/MultiSocketMonitor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,26 @@ MultiSocketMonitor::ClearSocketList() noexcept
#ifndef _WIN32

void
MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
MultiSocketMonitor::ReplaceSocketList(std::span<pollfd> 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
Expand Down
3 changes: 2 additions & 1 deletion src/event/MultiSocketMonitor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cassert>
#include <forward_list>
#include <iterator>
#include <span>

#ifndef _WIN32
struct pollfd;
Expand Down Expand Up @@ -190,7 +191,7 @@ public:
*
* May only be called from PrepareSockets().
*/
void ReplaceSocketList(pollfd *pfds, unsigned n) noexcept;
void ReplaceSocketList(std::span<pollfd> pfds) noexcept;
#endif

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/alsa/NonBlock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>(count)});
return Event::Duration(-1);
}

Expand Down Expand Up @@ -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<std::size_t>(count)});
return Event::Duration(-1);
}

Expand Down

0 comments on commit 9aa6b03

Please sign in to comment.