Skip to content

Commit

Permalink
Slice of IoSliceMut(s) must survive until submit
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder authored and withoutboats committed Dec 19, 2019
1 parent c783dec commit 8234739
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
extern crate test;

use std::fs::File;
use std::io;
use std::path::PathBuf;
use std::io::{self, IoSliceMut};
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::PathBuf;

const TEXT: &[u8] = b"I really wanna stop
But I just gotta taste for it
Expand All @@ -28,8 +28,10 @@ fn read_test() -> io::Result<()> {
path.push("text.txt");
let file = File::open(&path)?;
let mut buf1 = [0; 4096];

unsafe {
prep(&mut io_uring, &mut buf1, file.as_raw_fd())?;
let mut bufs = [io::IoSliceMut::new(&mut buf1)];
prep(&mut io_uring, &mut bufs, file.as_raw_fd())?;
}

let dirt = dirty_stack();
Expand All @@ -48,11 +50,10 @@ fn read_test() -> io::Result<()> {
}

#[inline(never)]
unsafe fn prep(ring: &mut iou::IoUring, buf: &mut [u8], fd: RawFd) -> io::Result<()> {
unsafe fn prep(ring: &mut iou::IoUring, bufs: &mut [IoSliceMut], fd: RawFd) -> io::Result<()> {
let mut sq = ring.sq();
let mut sqe = sq.next_sqe().unwrap();
let mut bufs = [io::IoSliceMut::new(buf)];
sqe.prep_read_vectored(fd, &mut bufs, 0);
sqe.prep_read_vectored(fd, bufs, 0);
sqe.set_user_data(0xDEADBEEF);
sq.submit()?;
Ok(())
Expand Down

0 comments on commit 8234739

Please sign in to comment.