autocommit 2022-02-15 22:53:12 CET
This commit is contained in:
parent
290225190a
commit
cacd49d15a
33 changed files with 884 additions and 220 deletions
|
|
@ -94,7 +94,6 @@ impl BufFdOut {
|
|||
) -> Result<(), BufFdError> {
|
||||
while buf.read_pos < buf.write_pos {
|
||||
if self.flush_sync(buf)? {
|
||||
self.fd.writable().await?;
|
||||
if timeout.is_none() {
|
||||
*timeout = Some(self.fd.eng().timeout(5000)?.fuse());
|
||||
}
|
||||
|
|
@ -157,6 +156,60 @@ impl BufFdOut {
|
|||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub async fn flush2(&mut self, buf: &[u8], fds: &mut Vec<OwnedFd>) -> Result<(), BufFdError> {
|
||||
let mut read_pos = 0;
|
||||
while read_pos < buf.len() {
|
||||
if self.flush_sync2(&mut read_pos, buf, fds)? {
|
||||
self.fd.writable().await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn flush_sync2(
|
||||
&mut self,
|
||||
read_pos: &mut usize,
|
||||
buf: &[u8],
|
||||
fds: &mut Vec<OwnedFd>,
|
||||
) -> Result<bool, BufFdError> {
|
||||
let mut cmsg_len = 0;
|
||||
let mut fds_opt = None;
|
||||
if fds.len() > 0 {
|
||||
self.fd_ids.clear();
|
||||
self.fd_ids.extend(fds.iter().map(|f| f.raw()));
|
||||
let hdr = c::cmsghdr {
|
||||
cmsg_len: 0,
|
||||
cmsg_level: c::SOL_SOCKET,
|
||||
cmsg_type: c::SCM_RIGHTS,
|
||||
};
|
||||
let mut cmsg_buf = &mut self.cmsg_buf[..];
|
||||
cmsg_len = uapi::cmsg_write(&mut cmsg_buf, hdr, &self.fd_ids[..]).unwrap();
|
||||
fds_opt = Some(fds);
|
||||
}
|
||||
while *read_pos < buf.len() {
|
||||
let buf = &buf[*read_pos..];
|
||||
let hdr = uapi::Msghdr {
|
||||
iov: slice::from_ref(&buf),
|
||||
control: Some(&self.cmsg_buf[..cmsg_len]),
|
||||
name: uapi::sockaddr_none_ref(),
|
||||
};
|
||||
let bytes_sent =
|
||||
match uapi::sendmsg(self.fd.raw(), &hdr, c::MSG_DONTWAIT | c::MSG_NOSIGNAL) {
|
||||
Ok(b) => {
|
||||
if let Some(fds) = fds_opt.take() {
|
||||
fds.clear();
|
||||
}
|
||||
b
|
||||
}
|
||||
Err(Errno(c::EAGAIN)) => return Ok(true),
|
||||
Err(Errno(c::ECONNRESET)) => return Err(BufFdError::Closed),
|
||||
Err(e) => return Err(BufFdError::Io(e.into())),
|
||||
};
|
||||
*read_pos += bytes_sent;
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for OutBuffer {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue