From 4680698ed28396da6fb90289f2961d4147f7d9ff Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 15 Jan 2018 21:01:37 -0700 Subject: [PATCH] aio: prefer polling over aio_suspend in the doc tests --- src/sys/aio.rs | 78 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/src/sys/aio.rs b/src/sys/aio.rs index eda6e1d2a7..1c9872bc73 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -191,15 +191,20 @@ impl<'a> AioCb<'a> { /// ``` /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify::SigevNone; + /// # use std::{thread, time}; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; /// # fn main() { /// let f = tempfile().unwrap(); /// let mut aiocb = AioCb::from_fd( f.as_raw_fd(), 0, SigevNone); /// aiocb.fsync(AioFsyncMode::O_SYNC).expect("aio_fsync failed early"); - /// aio_suspend(&[&aiocb], None).expect("aio_suspend failed"); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// aiocb.aio_return().expect("aio_fsync failed late"); /// # } /// ``` @@ -247,8 +252,11 @@ impl<'a> AioCb<'a> { /// ``` /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; + /// # use std::{thread, time}; /// # use std::io::Write; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; @@ -266,7 +274,9 @@ impl<'a> AioCb<'a> { /// SigevNotify::SigevNone, /// LioOpcode::LIO_NOP); /// aiocb.read().unwrap(); - /// aio_suspend(&[&aiocb], None).unwrap(); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// assert_eq!(aiocb.aio_return().unwrap() as usize, LEN); /// } /// assert_eq!(rbuf, b"cdef"); @@ -317,9 +327,12 @@ impl<'a> AioCb<'a> { /// # extern crate bytes; /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use bytes::Bytes; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; + /// # use std::{thread, time}; /// # use std::io::Write; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; @@ -333,7 +346,9 @@ impl<'a> AioCb<'a> { /// SigevNotify::SigevNone, /// LioOpcode::LIO_NOP); /// aiocb.write().unwrap(); - /// aio_suspend(&[&aiocb], None).unwrap(); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// assert_eq!(aiocb.aio_return().unwrap() as usize, wbuf.len()); /// # } /// ``` @@ -397,9 +412,12 @@ impl<'a> AioCb<'a> { /// # extern crate bytes; /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use bytes::BytesMut; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; + /// # use std::{thread, time}; /// # use std::io::Write; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; @@ -416,7 +434,9 @@ impl<'a> AioCb<'a> { /// SigevNotify::SigevNone, /// LioOpcode::LIO_NOP); /// aiocb.read().unwrap(); - /// aio_suspend(&[&aiocb], None).unwrap(); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// assert_eq!(aiocb.aio_return().unwrap() as usize, LEN); /// let buffer = aiocb.into_buffer(); /// const EXPECT: &[u8] = b"cdef"; @@ -554,8 +574,11 @@ impl<'a> AioCb<'a> { /// ``` /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; + /// # use std::{thread, time}; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; /// # fn main() { @@ -568,7 +591,9 @@ impl<'a> AioCb<'a> { /// SigevNotify::SigevNone, /// LioOpcode::LIO_NOP); /// aiocb.write().unwrap(); - /// aio_suspend(&[&aiocb], None).unwrap(); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len()); /// # } /// ``` @@ -647,9 +672,12 @@ impl<'a> AioCb<'a> { /// # extern crate bytes; /// # extern crate tempfile; /// # extern crate nix; + /// # use nix::errno::Errno; + /// # use nix::Error; /// # use bytes::Bytes; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; + /// # use std::{thread, time}; /// # use std::io::Write; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; @@ -665,7 +693,9 @@ impl<'a> AioCb<'a> { /// aiocb.write().unwrap(); /// let cs = aiocb.cancel().unwrap(); /// if cs == AioCancelStat::AioNotCanceled { - /// aio_suspend(&[&aiocb], None).unwrap(); + /// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { + /// thread::sleep(time::Duration::from_millis(10)); + /// } /// } /// // Must call `aio_return`, but ignore the result /// let _ = aiocb.aio_return(); @@ -843,9 +873,12 @@ impl<'a> AioCb<'a> { /// # extern crate bytes; /// # extern crate tempfile; /// # extern crate nix; +/// # use nix::errno::Errno; +/// # use nix::Error; /// # use bytes::Bytes; /// # use nix::sys::aio::*; /// # use nix::sys::signal::SigevNotify; +/// # use std::{thread, time}; /// # use std::io::Write; /// # use std::os::unix::io::AsRawFd; /// # use tempfile::tempfile; @@ -861,7 +894,9 @@ impl<'a> AioCb<'a> { /// aiocb.write().unwrap(); /// let cs = aio_cancel_all(f.as_raw_fd()).unwrap(); /// if cs == AioCancelStat::AioNotCanceled { -/// aio_suspend(&[&aiocb], None).unwrap(); +/// while (aiocb.error() == Err(Error::from(Errno::EINPROGRESS))) { +/// thread::sleep(time::Duration::from_millis(10)); +/// } /// } /// // Must call `aio_return`, but ignore the result /// let _ = aiocb.aio_return(); @@ -886,6 +921,35 @@ pub fn aio_cancel_all(fd: RawFd) -> Result { /// /// If `timeout` is `None`, `aio_suspend` will block indefinitely. /// +/// # Examples +/// +/// Use `aio_suspend` to block until an aio operation completes. +/// +// Disable doctest due to a known bug in FreeBSD's 32-bit emulation. The fix +// will be included in release 11.2, and we can reenable the doc test when the +// CI machine gets upgraded to that release. +// https://svnweb.freebsd.org/base?view=revision&revision=325018 +/// ```no_run +/// # extern crate tempfile; +/// # extern crate nix; +/// # use nix::sys::aio::*; +/// # use nix::sys::signal::SigevNotify; +/// # use std::os::unix::io::AsRawFd; +/// # use tempfile::tempfile; +/// # fn main() { +/// const WBUF: &[u8] = b"abcdef123456"; +/// let mut f = tempfile().unwrap(); +/// let mut aiocb = AioCb::from_slice( f.as_raw_fd(), +/// 2, //offset +/// WBUF, +/// 0, //priority +/// SigevNotify::SigevNone, +/// LioOpcode::LIO_NOP); +/// aiocb.write().unwrap(); +/// aio_suspend(&[&aiocb], None).expect("aio_suspend failed"); +/// assert_eq!(aiocb.aio_return().unwrap() as usize, WBUF.len()); +/// # } +/// ``` /// # References /// /// [`aio_suspend`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_suspend.html)