event/MultiSocketMonitor: pass std::span to ReplaceSocketList()
This commit is contained in:
parent
45f92f0ef0
commit
9aa6b03ba8
|
@ -66,27 +66,26 @@ MultiSocketMonitor::ClearSocketList() noexcept
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
||||||
void
|
void
|
||||||
MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
|
MultiSocketMonitor::ReplaceSocketList(std::span<pollfd> pfds) noexcept
|
||||||
{
|
{
|
||||||
#ifdef USE_EPOLL
|
#ifdef USE_EPOLL
|
||||||
always_ready_fds.clear();
|
always_ready_fds.clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pollfd *const end = pfds + n;
|
UpdateSocketList([pfds](SocketDescriptor fd) -> unsigned {
|
||||||
|
auto i = std::find_if(pfds.begin(), pfds.end(), [fd](const struct pollfd &pfd){
|
||||||
UpdateSocketList([pfds, end](SocketDescriptor fd) -> unsigned {
|
|
||||||
auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){
|
|
||||||
return pfd.fd == fd.Get();
|
return pfd.fd == fd.Get();
|
||||||
});
|
});
|
||||||
if (i == end)
|
|
||||||
|
if (i == pfds.end())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return std::exchange(i->events, 0);
|
return std::exchange(i->events, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto i = pfds; i != end; ++i)
|
for (const auto &i : pfds)
|
||||||
if (i->events != 0)
|
if (i.events != 0)
|
||||||
AddSocket(SocketDescriptor(i->fd), i->events);
|
AddSocket(SocketDescriptor(i.fd), i.events);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
struct pollfd;
|
struct pollfd;
|
||||||
|
@ -190,7 +191,7 @@ public:
|
||||||
*
|
*
|
||||||
* May only be called from PrepareSockets().
|
* May only be called from PrepareSockets().
|
||||||
*/
|
*/
|
||||||
void ReplaceSocketList(pollfd *pfds, unsigned n) noexcept;
|
void ReplaceSocketList(std::span<pollfd> pfds) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
|
||||||
throw Alsa::MakeError(count, "snd_pcm_poll_descriptors() failed");
|
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);
|
return Event::Duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ AlsaNonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noe
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
m.ReplaceSocketList(pfds, count);
|
m.ReplaceSocketList({pfds, static_cast<std::size_t>(count)});
|
||||||
return Event::Duration(-1);
|
return Event::Duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue