Skip to content

Commit 9aa6b03

Browse files
committed
event/MultiSocketMonitor: pass std::span to ReplaceSocketList()
1 parent 45f92f0 commit 9aa6b03

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/event/MultiSocketMonitor.cxx

+8-9
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,26 @@ MultiSocketMonitor::ClearSocketList() noexcept
6666
#ifndef _WIN32
6767

6868
void
69-
MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
69+
MultiSocketMonitor::ReplaceSocketList(std::span<pollfd> pfds) noexcept
7070
{
7171
#ifdef USE_EPOLL
7272
always_ready_fds.clear();
7373
#endif
7474

75-
pollfd *const end = pfds + n;
76-
77-
UpdateSocketList([pfds, end](SocketDescriptor fd) -> unsigned {
78-
auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){
75+
UpdateSocketList([pfds](SocketDescriptor fd) -> unsigned {
76+
auto i = std::find_if(pfds.begin(), pfds.end(), [fd](const struct pollfd &pfd){
7977
return pfd.fd == fd.Get();
8078
});
81-
if (i == end)
79+
80+
if (i == pfds.end())
8281
return 0;
8382

8483
return std::exchange(i->events, 0);
8584
});
8685

87-
for (auto i = pfds; i != end; ++i)
88-
if (i->events != 0)
89-
AddSocket(SocketDescriptor(i->fd), i->events);
86+
for (const auto &i : pfds)
87+
if (i.events != 0)
88+
AddSocket(SocketDescriptor(i.fd), i.events);
9089
}
9190

9291
#endif

src/event/MultiSocketMonitor.hxx

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cassert>
1313
#include <forward_list>
1414
#include <iterator>
15+
#include <span>
1516

1617
#ifndef _WIN32
1718
struct pollfd;
@@ -190,7 +191,7 @@ public:
190191
*
191192
* May only be called from PrepareSockets().
192193
*/
193-
void ReplaceSocketList(pollfd *pfds, unsigned n) noexcept;
194+
void ReplaceSocketList(std::span<pollfd> pfds) noexcept;
194195
#endif
195196

196197
/**

src/lib/alsa/NonBlock.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
2626
throw Alsa::MakeError(count, "snd_pcm_poll_descriptors() failed");
2727
}
2828

29-
m.ReplaceSocketList(pfds, count);
29+
m.ReplaceSocketList({pfds, static_cast<std::size_t>(count)});
3030
return Event::Duration(-1);
3131
}
3232

@@ -71,7 +71,7 @@ AlsaNonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noe
7171
if (count < 0)
7272
count = 0;
7373

74-
m.ReplaceSocketList(pfds, count);
74+
m.ReplaceSocketList({pfds, static_cast<std::size_t>(count)});
7575
return Event::Duration(-1);
7676
}
7777

0 commit comments

Comments
 (0)