Skip to content

Commit

Permalink
refactor: use pread and pwrite for legacy path
Browse files Browse the repository at this point in the history
  • Loading branch information
ihciah committed Jul 12, 2023
1 parent d1e80e2 commit d82a133
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 46 deletions.
32 changes: 8 additions & 24 deletions monoio/src/driver/op/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,14 @@ impl<T: IoBufMut> OpAble for Read<T> {
#[cfg(all(unix, feature = "legacy"))]
fn legacy_call(&mut self) -> io::Result<u32> {
let fd = self.fd.as_raw_fd();
if self.offset != 0 {
let seek_offset = libc::off_t::try_from(self.offset)
.map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?;
let neg_seek_offset = seek_offset
.checked_neg()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "offset too big"))?;
syscall_u32!(lseek(fd, seek_offset, libc::SEEK_CUR))?;
syscall_u32!(read(
fd,
self.buf.write_ptr() as _,
self.buf.bytes_total().min(u32::MAX as usize)
))
.map_err(|e| {
// seek back if read fail...
let _ = syscall_u32!(lseek(fd, neg_seek_offset, libc::SEEK_CUR));
e
})
} else {
syscall_u32!(read(
fd,
self.buf.write_ptr() as _,
self.buf.bytes_total().min(u32::MAX as usize)
))
}
let seek_offset = libc::off_t::try_from(self.offset)
.map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?;
syscall_u32!(pread64(

Check failure on line 79 in monoio/src/driver/op/read.rs

View workflow job for this annotation

GitHub Actions / Run cargo test on macos

cannot find function `pread64` in crate `libc`
fd,
self.buf.write_ptr() as _,
self.buf.bytes_total(),
seek_offset
))
}
}

Expand Down
28 changes: 6 additions & 22 deletions monoio/src/driver/op/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,12 @@ impl<T: IoBuf> OpAble for Write<T> {
let fd = self.fd.as_raw_fd();
let seek_offset = libc::off_t::try_from(self.offset)
.map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?;
let neg_seek_offset = seek_offset
.checked_neg()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "offset too big"))?;
if self.offset != 0 {
syscall_u32!(lseek(fd, seek_offset, libc::SEEK_CUR))?;
syscall_u32!(write(
fd,
self.buf.read_ptr() as _,
self.buf.bytes_init().min(u32::MAX as usize)
))
.map_err(|e| {
// seek back if read fail...
let _ = syscall_u32!(lseek(fd, neg_seek_offset, libc::SEEK_CUR));
e
})
} else {
syscall_u32!(write(
fd,
self.buf.read_ptr() as _,
self.buf.bytes_init().min(u32::MAX as usize)
))
}
syscall_u32!(pwrite64(

Check failure on line 66 in monoio/src/driver/op/write.rs

View workflow job for this annotation

GitHub Actions / Run cargo test on macos

cannot find function `pwrite64` in crate `libc`
fd,
self.buf.read_ptr() as _,
self.buf.bytes_init(),
seek_offset
))
}
}

Expand Down

0 comments on commit d82a133

Please sign in to comment.