use std::{
fs::OpenOptions,
io::{Read, Write},
os::windows::prelude::{FromRawHandle, OpenOptionsExt},
sync::atomic::{AtomicUsize, Ordering},
};
use std::io::Result;
use bytes::{Buf, BufMut}; use mio::windows::NamedPipe; use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OVERLAPPED;
usecrate::PlatformHandle;
usesuper::{ConnectionBuffer, RecvMsg, SendMsg};
pubstruct Pipe { pub(crate) io: NamedPipe,
}
// Create a connected "pipe" pair. The `Pipe` is the server end, // the `PlatformHandle` is the client end to be remoted. pubfn make_pipe_pair() -> Result<(Pipe, PlatformHandle)> { let pipe_name = get_pipe_name(); let server = NamedPipe::new(&pipe_name)?;
let client = { letmut opts = OpenOptions::new();
opts.read(true)
.write(true)
.custom_flags(FILE_FLAG_OVERLAPPED); let file = opts.open(&pipe_name)?;
PlatformHandle::from(file)
};
impl RecvMsg for Pipe { // Receive data from the associated connection. `recv_msg` expects the capacity of // the `ConnectionBuffer` members has been adjusted appropriate by the caller. fn recv_msg(&mutself, buf: &mut ConnectionBuffer) -> Result<usize> {
assert!(buf.buf.remaining_mut() > 0); let r = unsafe { let chunk = buf.buf.chunk_mut(); let slice = std::slice::from_raw_parts_mut(chunk.as_mut_ptr(), chunk.len()); self.io.read(slice)
}; match r {
Ok(n) => unsafe {
buf.buf.advance_mut(n);
Ok(n)
},
e => e,
}
}
}
impl SendMsg for Pipe { // Send data on the associated connection. `send_msg` adjusts the length of the // `ConnectionBuffer` members based on the size of the successful send operation. fn send_msg(&mutself, buf: &mut ConnectionBuffer) -> Result<usize> {
assert!(!buf.buf.is_empty()); let r = self.io.write(&buf.buf[..buf.buf.len()]); iflet Ok(n) = r {
buf.buf.advance(n); whilelet Some(mut handle) = buf.pop_handle() {
handle.mark_sent()
}
}
r
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-22)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.