From 0c9437338dbf36bb29d52e37e0c952ea1d55d800 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Sep 2017 14:27:20 -0600 Subject: AioCb::Drop will now panic for in-progress AioCb Printing a warning message to stderr isn't really appropriate, because there's no way to guarantee that stderr is even valid. Nor is aio_suspend necessarily an appropriate action to take. --- src/sys/aio.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/sys/aio.rs b/src/sys/aio.rs index abb742f3..5d56f1cd 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -4,8 +4,6 @@ use libc::{c_void, off_t, size_t}; use libc; use std::fmt; use std::fmt::Debug; -use std::io::Write; -use std::io::stderr; use std::marker::PhantomData; use std::mem; use std::rc::Rc; @@ -332,24 +330,8 @@ impl<'a> Debug for AioCb<'a> { impl<'a> Drop for AioCb<'a> { /// If the `AioCb` has no remaining state in the kernel, just drop it. - /// Otherwise, collect its error and return values, so as not to leak - /// resources. + /// Otherwise, dropping constitutes a resource leak, which is an error fn drop(&mut self) { - if self.in_progress { - // Well-written programs should never get here. They should always - // wait for an AioCb to complete before dropping it - let _ = write!(stderr(), "WARNING: dropped an in-progress AioCb"); - loop { - let ret = aio_suspend(&[&self], None); - match ret { - Ok(()) => break, - Err(Error::Sys(Errno::EINVAL)) => panic!( - "Inconsistent AioCb.in_progress value"), - Err(Error::Sys(Errno::EINTR)) => (), // Retry interrupted syscall - _ => panic!("Unexpected aio_suspend return value {:?}", ret) - }; - } - let _ = self.aio_return(); - } + assert!(!self.in_progress, "Dropped an in-progress AioCb"); } } -- cgit v1.2.3 From bd2cda18cec3d2acb1f7bb37778be557029b0268 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Sep 2017 14:27:57 -0600 Subject: Fixed error handling in `AioCb::{fsync,read,write}` Previously, the `AioCb`'s `in_progress` field would erroneously be set to `true`, even if the syscall had an error Fixes #714 --- src/sys/aio.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 5d56f1cd..22bd3959 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -232,16 +232,22 @@ impl<'a> AioCb<'a> { /// An asynchronous version of `fsync`. pub fn fsync(&mut self, mode: AioFsyncMode) -> Result<()> { let p: *mut libc::aiocb = &mut self.aiocb; - self.in_progress = true; - Errno::result(unsafe { libc::aio_fsync(mode as libc::c_int, p) }).map(drop) + Errno::result(unsafe { + libc::aio_fsync(mode as libc::c_int, p) + }).map(|_| { + self.in_progress = true; + }) } /// Asynchronously reads from a file descriptor into a buffer pub fn read(&mut self) -> Result<()> { assert!(self.mutable, "Can't read into an immutable buffer"); let p: *mut libc::aiocb = &mut self.aiocb; - self.in_progress = true; - Errno::result(unsafe { libc::aio_read(p) }).map(drop) + Errno::result(unsafe { + libc::aio_read(p) + }).map(|_| { + self.in_progress = true; + }) } /// Retrieve return status of an asynchronous operation. Should only be @@ -257,8 +263,11 @@ impl<'a> AioCb<'a> { /// Asynchronously writes from a buffer to a file descriptor pub fn write(&mut self) -> Result<()> { let p: *mut libc::aiocb = &mut self.aiocb; - self.in_progress = true; - Errno::result(unsafe { libc::aio_write(p) }).map(drop) + Errno::result(unsafe { + libc::aio_write(p) + }).map(|_| { + self.in_progress = true; + }) } } -- cgit v1.2.3