1
0
Fork 0
forked from wry/wry

autocommit 2022-02-15 22:53:12 CET

This commit is contained in:
Julian Orth 2022-02-15 22:53:12 +01:00
parent 290225190a
commit cacd49d15a
33 changed files with 884 additions and 220 deletions

View file

@ -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 {

View file

@ -15,7 +15,7 @@ impl<K, V> Default for CopyHashMap<K, V> {
}
}
impl<K: Eq + Hash, V: Clone> CopyHashMap<K, V> {
impl<K: Eq + Hash, V> CopyHashMap<K, V> {
pub fn new() -> Self {
Self::default()
}
@ -24,7 +24,10 @@ impl<K: Eq + Hash, V: Clone> CopyHashMap<K, V> {
self.map.borrow_mut().insert(k, v);
}
pub fn get(&self, k: &K) -> Option<V> {
pub fn get(&self, k: &K) -> Option<V>
where
V: Clone,
{
self.map.borrow_mut().get(k).cloned()
}

View file

@ -219,7 +219,8 @@ impl<T> NodeRef<T> {
}
fn peer<F>(&self, peer: F) -> Option<NodeRef<T>>
where F: FnOnce(&NodeData<T>) -> &Cell<NonNull<NodeData<T>>>,
where
F: FnOnce(&NodeData<T>) -> &Cell<NonNull<NodeData<T>>>,
{
unsafe {
let data = self.data.as_ref();

View file

@ -10,5 +10,5 @@ pub mod numcell;
pub mod ptr_ext;
pub mod queue;
pub mod smallmap;
pub mod vec_ext;
pub mod stack;
pub mod vec_ext;

View file

@ -10,6 +10,12 @@ pub struct AsyncQueue<T> {
waiters: RefCell<Vec<Waker>>,
}
impl<T> Default for AsyncQueue<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> AsyncQueue<T> {
pub fn new() -> Self {
Self {

View file

@ -1,5 +1,5 @@
use std::cell::UnsafeCell;
use crate::utils::ptr_ext::MutPtrExt;
use std::cell::UnsafeCell;
pub struct Stack<T> {
vec: UnsafeCell<Vec<T>>,
@ -21,8 +21,6 @@ impl<T> Stack<T> {
}
pub fn pop(&self) -> Option<T> {
unsafe {
self.vec.get().deref_mut().pop()
}
unsafe { self.vec.get().deref_mut().pop() }
}
}