Make sure that all writes succeed

This commit is contained in:
Pierre Krieger 2015-09-22 21:01:26 +02:00
parent 5fc346b34b
commit 6bd28231ec
1 changed files with 4 additions and 3 deletions

View File

@ -333,15 +333,15 @@ impl<'a, T> Buffer<'a, T> {
} }
pub fn finish(self) { pub fn finish(self) {
let written = (self.buffer.len() / self.channel.num_channels as usize) let to_write = (self.buffer.len() / self.channel.num_channels as usize)
as alsa::snd_pcm_uframes_t; as alsa::snd_pcm_uframes_t;
let channel = self.channel.channel.lock().unwrap(); let channel = self.channel.channel.lock().unwrap();
unsafe { unsafe {
loop { loop {
let result = alsa::snd_pcm_writei(*channel, let result = alsa::snd_pcm_writei(*channel,
self.buffer.as_ptr() as *const libc::c_void, self.buffer.as_ptr() as *const libc::c_void,
written); to_write);
if result == -32 { if result == -32 {
// buffer underrun // buffer underrun
@ -349,6 +349,7 @@ impl<'a, T> Buffer<'a, T> {
} else if result < 0 { } else if result < 0 {
check_errors(result as libc::c_int).unwrap(); check_errors(result as libc::c_int).unwrap();
} else { } else {
assert_eq!(result as alsa::snd_pcm_uframes_t, to_write);
break; break;
} }
} }