Skip to content

Commit

Permalink
Merge pull request #231 from Berrysoft/fix/iour-op
Browse files Browse the repository at this point in the history
fix(driver,iour): wrong impl of WriteVectoredAt
  • Loading branch information
Berrysoft authored Mar 25, 2024
2 parents 3535a5a + b88a115 commit 5e185ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compio-driver/src/iour/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<T: IoVectoredBuf> OpCode for WriteVectoredAt<T> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
let this = unsafe { self.get_unchecked_mut() };
this.slices = unsafe { this.buffer.as_io_slices() };
opcode::Write::new(
opcode::Writev::new(
Fd(this.fd),
this.slices.as_ptr() as _,
this.slices.len() as _,
Expand Down
17 changes: 16 additions & 1 deletion compio-fs/tests/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::prelude::*;

use compio_fs::File;
use compio_io::{AsyncReadAtExt, AsyncWriteAtExt};
use compio_io::{AsyncReadAtExt, AsyncWriteAt, AsyncWriteAtExt};
use tempfile::NamedTempFile;

#[compio_macros::test]
Expand Down Expand Up @@ -51,6 +51,21 @@ async fn basic_write() {
assert_eq!(file, HELLO);
}

#[compio_macros::test]
async fn writev() {
let tempfile = tempfile();

let mut file = File::create(tempfile.path()).await.unwrap();

let (write, _) = file.write_vectored_at([HELLO, HELLO], 0).await.unwrap();
assert_eq!(write, HELLO.len() * 2);
file.sync_all().await.unwrap();

let file = std::fs::read(tempfile.path()).unwrap();
assert_eq!(&file[..HELLO.len()], HELLO);
assert_eq!(&file[HELLO.len()..], HELLO);
}

#[compio_macros::test]
async fn cancel_read() {
let mut tempfile = tempfile();
Expand Down

0 comments on commit 5e185ba

Please sign in to comment.