Skip to content

Commit

Permalink
aio: prefer polling over aio_suspend in the doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Jan 16, 2018
1 parent e6a20fd commit 4680698
Showing 1 changed file with 71 additions and 7 deletions.
78 changes: 71 additions & 7 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
/// # }
/// ```
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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());
/// # }
/// ```
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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() {
Expand All @@ -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());
/// # }
/// ```
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -886,6 +921,35 @@ pub fn aio_cancel_all(fd: RawFd) -> Result<AioCancelStat> {
///
/// 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

This comment has been minimized.

Copy link
@Susurrus

Susurrus Jan 16, 2018

Contributor

Can you mark this as FIXME: so it'll be easy to find using grep later?

// 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)
Expand Down

0 comments on commit 4680698

Please sign in to comment.