Skip to content

Commit

Permalink
rename lifetime from a to fd
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Dec 4, 2023
1 parent 9e9d928 commit 2ce7f8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/sys/sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ cfg_if! {

#[derive(Debug, Copy, Clone)]
/// Mapping of the raw C sendfilevec_t struct
pub struct SendfileVec<'a> {
pub struct SendfileVec<'fd> {
raw: libc::sendfilevec_t,
phantom: PhantomData<BorrowedFd<'a>>
phantom: PhantomData<BorrowedFd<'fd>>
}

impl<'fd> SendfileVec<'fd> {
Expand All @@ -136,18 +136,16 @@ cfg_if! {
off: off_t,
len: usize
) -> Self {
// The file descriptor here relates to C's SFV_FD_SELF
Self{raw: libc::sendfilevec_t{sfv_fd: -2, sfv_flag: 0, sfv_off: off, sfv_len: len}, phantom: PhantomData}
Self{raw: libc::sendfilevec_t{sfv_fd: libc::SFV_FD_SELF, sfv_flag: 0, sfv_off: off, sfv_len: len}, phantom: PhantomData}
}

/// initialises SendfileVec to send data from `fd`.
pub fn new<F: AsFd>(
fd: &'fd F,
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: bfd.as_raw_fd(), sfv_flag: 0, sfv_off:off, sfv_len: len}, phantom: PhantomData}
Self{raw: libc::sendfilevec_t{sfv_fd: fd.as_raw_fd(), sfv_flag: 0, sfv_off:off, sfv_len: len}, phantom: PhantomData}
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/test_sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ fn test_sendfile_darwin() {
#[cfg(solarish)]
#[test]
fn test_sendfilev() {
use std::os::fd::AsFd;
// Declare the content
let header_strings =
["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"];
Expand All @@ -230,17 +231,17 @@ fn test_sendfilev() {
let (mut rd, wr) = UnixStream::pair().unwrap();
let vec: &[SendfileVec] = &[
SendfileVec::new(
&header_data,
header_data.as_fd(),
0,
header_strings.iter().map(|s| s.len()).sum(),
),
SendfileVec::new(
&body_data,
body_data.as_fd(),
body_offset as off_t,
body.len() - body_offset,
),
SendfileVec::new(
&trailer_data,
trailer_data.as_fd(),
0,
trailer_strings.iter().map(|s| s.len()).sum(),
),
Expand Down

0 comments on commit 2ce7f8b

Please sign in to comment.