From 6bd28231ec697be5807740bebbe34fee4a709932 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 22 Sep 2015 21:01:26 +0200 Subject: [PATCH] Make sure that all writes succeed --- src/alsa/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index c527f6b..dd1b8a5 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -333,15 +333,15 @@ impl<'a, T> Buffer<'a, T> { } pub fn finish(self) { - let written = (self.buffer.len() / self.channel.num_channels as usize) - as alsa::snd_pcm_uframes_t; + let to_write = (self.buffer.len() / self.channel.num_channels as usize) + as alsa::snd_pcm_uframes_t; let channel = self.channel.channel.lock().unwrap(); unsafe { loop { let result = alsa::snd_pcm_writei(*channel, self.buffer.as_ptr() as *const libc::c_void, - written); + to_write); if result == -32 { // buffer underrun @@ -349,6 +349,7 @@ impl<'a, T> Buffer<'a, T> { } else if result < 0 { check_errors(result as libc::c_int).unwrap(); } else { + assert_eq!(result as alsa::snd_pcm_uframes_t, to_write); break; } }