From 5cb603983e2e20f1d2f9f638be55e945c90bd6b4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 4 Dec 2018 18:00:52 +0100 Subject: [PATCH] alsa/NonBlock: throw on snd_pcm_poll_descriptors_revents() error This function is sparsely documented and a look at the bluez-alsa source code shows that implementations make undocumented assumptions on the `struct pollfd` array parameter which can lead to strange effects. --- src/lib/alsa/NonBlock.cxx | 7 +++++-- src/lib/alsa/NonBlock.hxx | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/alsa/NonBlock.cxx b/src/lib/alsa/NonBlock.cxx index 3f4a4adc0..7bc1b225b 100644 --- a/src/lib/alsa/NonBlock.cxx +++ b/src/lib/alsa/NonBlock.cxx @@ -50,7 +50,7 @@ AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) void AlsaNonBlockPcm::DispatchSockets(MultiSocketMonitor &m, - snd_pcm_t *pcm) noexcept + snd_pcm_t *pcm) { int count = snd_pcm_poll_descriptors_count(pcm); if (count <= 0) @@ -69,7 +69,10 @@ AlsaNonBlockPcm::DispatchSockets(MultiSocketMonitor &m, }); unsigned short dummy; - snd_pcm_poll_descriptors_revents(pcm, pfds, i - pfds, &dummy); + int err = snd_pcm_poll_descriptors_revents(pcm, pfds, i - pfds, &dummy); + if (err < 0) + throw FormatRuntimeError("snd_pcm_poll_descriptors_revents() failed: %s", + snd_strerror(-err)); } std::chrono::steady_clock::duration diff --git a/src/lib/alsa/NonBlock.hxx b/src/lib/alsa/NonBlock.hxx index 6b9f8f940..0242c0f8a 100644 --- a/src/lib/alsa/NonBlock.hxx +++ b/src/lib/alsa/NonBlock.hxx @@ -45,8 +45,10 @@ public: /** * Wrapper for snd_pcm_poll_descriptors_revents(), to be * called from MultiSocketMonitor::DispatchSockets(). + * + * Throws on error. */ - void DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) noexcept; + void DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm); }; /**