Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unix pipe. #91

Merged
merged 9 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compio-driver/src/iour/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<T: IoBufMut> OpCode for ReadAt<T> {
let fd = Fd(self.fd);
let slice = self.buffer.as_uninit_slice();
opcode::Read::new(fd, slice.as_mut_ptr() as _, slice.len() as _)
.offset(self.offset as _)
.offset(self.offset())
.build()
}
}
Expand All @@ -30,7 +30,7 @@ impl<T: IoBuf> OpCode for WriteAt<T> {
fn create_entry(self: Pin<&mut Self>) -> Entry {
let slice = self.buffer.as_slice();
opcode::Write::new(Fd(self.fd), slice.as_ptr(), slice.len() as _)
.offset(self.offset as _)
.offset(self.offset())
.build()
}
}
Expand Down
15 changes: 4 additions & 11 deletions compio-driver/src/poll/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T: IoBufMut> OpCode for ReadAt<T> {
fd,
slice.as_mut_ptr() as _,
slice.len() as _,
self.offset as _
self.offset()
))? as _))
} else {
Ok(Decision::wait_readable(self.fd))
Expand All @@ -33,14 +33,7 @@ impl<T: IoBufMut> OpCode for ReadAt<T> {
let fd = self.fd;
let slice = self.buffer.as_uninit_slice();

syscall!(
break pread(
fd,
slice.as_mut_ptr() as _,
slice.len() as _,
self.offset as _
)
)
syscall!(break pread(fd, slice.as_mut_ptr() as _, slice.len() as _, self.offset()))
}
}

Expand All @@ -52,7 +45,7 @@ impl<T: IoBuf> OpCode for WriteAt<T> {
self.fd,
slice.as_ptr() as _,
slice.len() as _,
self.offset as _
self.offset()
))? as _))
} else {
Ok(Decision::wait_writable(self.fd))
Expand All @@ -69,7 +62,7 @@ impl<T: IoBuf> OpCode for WriteAt<T> {
self.fd,
slice.as_ptr() as _,
slice.len() as _,
self.offset as _
self.offset()
)
)
}
Expand Down
24 changes: 21 additions & 3 deletions compio-driver/src/unix/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@ use compio_buf::{IntoInner, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
use libc::{sockaddr_storage, socklen_t};
use socket2::SockAddr;

#[cfg(doc)]
use crate::op::*;
use crate::RawFd;
use crate::{op::*, RawFd};

impl<T: IoBufMut> ReadAt<T> {
pub(crate) fn offset(&self) -> u64 {
if self.offset == usize::MAX {
u64::MAX
} else {
self.offset as _
}
}
}

impl<T: IoBuf> WriteAt<T> {
pub(crate) fn offset(&self) -> u64 {
if self.offset == usize::MAX {
u64::MAX
} else {
self.offset as _
}
}
}

/// Accept a connection.
pub struct Accept {
Expand Down
13 changes: 9 additions & 4 deletions compio-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ windows-sys = { version = "0.48", features = [
"Win32_System_SystemServices",
] }

# Windows specific dev dependencies
[target.'cfg(target_os = "windows")'.dev-dependencies]
windows-sys = { version = "0.48", features = ["Win32_Security_Authorization"] }

# Unix specific dependencies
[target.'cfg(unix)'.dependencies]
libc = "0.2"
os_pipe = "1"

# Shared dev dependencies for all platforms
[dev-dependencies]
compio-runtime = { workspace = true, features = ["time"] }
futures-util = "0.3"

# Windows specific dev dependencies
[target.'cfg(target_os = "windows")'.dev-dependencies]
windows-sys = { version = "0.48", features = ["Win32_Security_Authorization"] }

# Unix specific dev dependencies
[target.'cfg(unix)'.dev-dependencies]
nix = { version = "0.27", features = ["fs"] }

[features]
runtime = ["dep:compio-buf", "dep:compio-runtime"]

Expand Down
3 changes: 3 additions & 0 deletions compio-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ pub use open_options::*;

#[cfg(target_os = "windows")]
pub mod named_pipe;

#[cfg(unix)]
pub mod pipe;
Loading
Loading