-
Notifications
You must be signed in to change notification settings - Fork 666
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
sys::sendfile adding solaris' sendfilev wrapper proposal. #2207
Conversation
0893fd1
to
791a613
Compare
593c1d4
to
6f87e54
Compare
d06ad38
to
47a76ab
Compare
src/sys/sendfile.rs
Outdated
|
||
/// initialises SendfileVec to send data from `fd`. | ||
pub fn new<F: AsFd>( | ||
fd: F, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't capture anything about fd's lifetime. With this API, it's possible to use a RawFd after the file has been closed. That's why I suggested using BorrowedFd. You might be able to do it, without additional runtime cost, like this:
pub struct SendfileVec<'a> {
raw: libc::sendfilevec_t,
phantom: PhantomData<BorrowedFd<'a>>
}
pub fn new<F: AsFd, 'a>(fd: &'a F, off: off_t, len: usize) -> Self<'a> {
let bfd = fd.as_fd();
Self{raw: libc::sendfilevec_t{sfv_fd: bfd.as_raw_fd(), ...}, phantom: PhantomData}}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use BorrowedFd<'a>
here so that it is consistent with FdSet
and PollFd
BTW, I think we should also do this to Epoll
47a76ab
to
7f85f0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! It looks a lot more efficient now.
src/sys/sendfile.rs
Outdated
phantom: PhantomData<BorrowedFd<'a>> | ||
} | ||
|
||
const SFV_FD_SELF: i32 = -2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constants like this should be defined in the libc crate, not in Nix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I know I just did a PR for it tough :)
7f85f0d
to
8759d59
Compare
src/sys/sendfile.rs
Outdated
|
||
/// initialises SendfileVec to send data from `fd`. | ||
pub fn new<F: AsFd>( | ||
fd: F, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use BorrowedFd<'a>
here so that it is consistent with FdSet
and PollFd
BTW, I think we should also do this to Epoll
src/sys/sendfile.rs
Outdated
|
||
const SFV_FD_SELF: i32 = -2; | ||
|
||
impl<'a> SendfileVec<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it would be great if we rename this lifetime parameter to 'fd
given that libc::sendfilevec_t.sfv_fd
is a file descriptor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use BorrowedFd<'a> here so that it is consistent with FdSet and PollFd
BTW, I think we should also do this to Epoll
You re seing an old version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emmm, why did you revert the definition of SendfileVec
, for that BorrowedFd
, I was just suggesting changing the function parameter type to BorrowedFd<'fd>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like what we did to FdSet
:
Lines 18 to 47 in 39ad47b
pub struct FdSet<'fd> { | |
set: libc::fd_set, | |
_fd: std::marker::PhantomData<BorrowedFd<'fd>>, | |
} | |
fn assert_fd_valid(fd: RawFd) { | |
assert!( | |
usize::try_from(fd).map_or(false, |fd| fd < FD_SETSIZE), | |
"fd must be in the range 0..FD_SETSIZE", | |
); | |
} | |
impl<'fd> FdSet<'fd> { | |
/// Create an empty `FdSet` | |
pub fn new() -> FdSet<'fd> { | |
let mut fdset = mem::MaybeUninit::uninit(); | |
unsafe { | |
libc::FD_ZERO(fdset.as_mut_ptr()); | |
Self { | |
set: fdset.assume_init(), | |
_fd: std::marker::PhantomData, | |
} | |
} | |
} | |
/// Add a file descriptor to an `FdSet` | |
pub fn insert(&mut self, fd: BorrowedFd<'fd>) { | |
assert_fd_valid(fd.as_raw_fd()); | |
unsafe { libc::FD_SET(fd.as_raw_fd(), &mut self.set) }; | |
} |
Add label |
Do we need to tough ? I can just use directly the value if that s a problem. |
8759d59
to
74e8d44
Compare
Could you please elaborate on this? I don't think I fully understand this sentence |
I meant blocking because of libc. |
Nix does not define these constants ourselves, we add them to libc, and wait for a release of libc with the patch included, then we merge the Nix PR |
I no longer define this constant but just the value directly for the time being. but if you insist on waiting the next libc crate release, fine by me. |
Yes, we should wait for the libc release rather than using a magic number here |
Hi @devnexen, We now use the libc dependency from git, so you use the libc constant in this PR |
src/sys/sendfile.rs
Outdated
/// initialises SendfileVec to send data from `fd`. | ||
pub fn new<F: AsFd>( | ||
fd: &'fd F, | ||
off: off_t, | ||
len: usize | ||
) -> SendfileVec<'fd> { | ||
let bfd = fd.as_fd(); | ||
Self{raw: libc::sendfilevec_t{sfv_fd: bfd.as_raw_fd(), sfv_flag: 0, sfv_off:off, sfv_len: len}, phantom: PhantomData} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// initialises SendfileVec to send data from `fd`. | |
pub fn new<F: AsFd>( | |
fd: &'fd F, | |
off: off_t, | |
len: usize | |
) -> SendfileVec<'fd> { | |
let bfd = fd.as_fd(); | |
Self{raw: libc::sendfilevec_t{sfv_fd: bfd.as_raw_fd(), sfv_flag: 0, sfv_off:off, sfv_len: len}, phantom: PhantomData} | |
} | |
/// initialises SendfileVec to send data from `fd`. | |
pub fn new( | |
fd: BorrowedFd<'fd>, | |
off: off_t, | |
len: usize | |
) -> SendfileVec<'fd> { | |
let bfd = fd.as_fd(); | |
Self{raw: libc::sendfilevec_t{sfv_fd: fd.as_raw_fd(), sfv_flag: 0, sfv_off:off, sfv_len: len}, phantom: PhantomData} | |
} |
We should use a BorrowedFd<'fd>
here to be consistent with our other interfaces
hmmm ok sure. |
5cb41e5
to
2ce7f8b
Compare
2ce7f8b
to
f8c3b40
Compare
No description provided.