pub struct NamedPipeServer { /* private fields */ }fs and Windows only.Expand description
A Windows named pipe server.
Accepting client connections involves creating a server with
ServerOptions::create and waiting for clients to connect using
NamedPipeServer::connect.
To avoid having clients sporadically fail with
std::io::ErrorKind::NotFound when they connect to a server, we must
ensure that at least one server instance is available at all times. This
means that the typical listen loop for a server is a bit involved, because
we have to ensure that we never drop a server accidentally while a client
might connect.
So a correctly implemented server looks like this:
use std::io;
use compio_fs::named_pipe::ServerOptions;
const PIPE_NAME: &str = r"\\.\pipe\named-pipe-idiomatic-server";
// The first server needs to be constructed early so that clients can
// be correctly connected. Otherwise calling .wait will cause the client to
// error.
//
// Here we also make use of `first_pipe_instance`, which will ensure that
// there are no other servers up and running already.
let mut server = ServerOptions::new()
.first_pipe_instance(true)
.create(PIPE_NAME)?;
// Spawn the server loop.
loop {
// Wait for a client to connect.
let connected = server.connect().await?;
// Construct the next server to be connected before sending the one
// we already have of onto a task. This ensures that the server
// isn't closed (after it's done in the task) before a new one is
// available. Otherwise the client might error with
// `io::ErrorKind::NotFound`.
server = ServerOptions::new().create(PIPE_NAME)?;
let client = compio_runtime::spawn(async move {
// use the connected client
});
}Implementations§
Source§impl NamedPipeServer
impl NamedPipeServer
Sourcepub fn info(&self) -> Result<PipeInfo, Error>
pub fn info(&self) -> Result<PipeInfo, Error>
Retrieves information about the named pipe the server is associated with.
use compio_fs::named_pipe::{PipeEnd, PipeMode, ServerOptions};
const PIPE_NAME: &str = r"\\.\pipe\compio-named-pipe-server-info";
let server = ServerOptions::new()
.pipe_mode(PipeMode::Message)
.max_instances(5)
.create(PIPE_NAME)?;
let server_info = server.info()?;
assert_eq!(server_info.end, PipeEnd::Server);
assert_eq!(server_info.mode, PipeMode::Message);
assert_eq!(server_info.max_instances, 5);Sourcepub async fn connect(&self) -> Result<(), Error>
pub async fn connect(&self) -> Result<(), Error>
Enables a named pipe server process to wait for a client process to connect to an instance of a named pipe. A client process connects by creating a named pipe with the same name.
This corresponds to the ConnectNamedPipe system call.
§Example
use compio_fs::named_pipe::ServerOptions;
const PIPE_NAME: &str = r"\\.\pipe\mynamedpipe";
let pipe = ServerOptions::new().create(PIPE_NAME)?;
// Wait for a client to connect.
pipe.connect().await?;
// Use the connected client...Sourcepub fn disconnect(&self) -> Result<(), Error>
pub fn disconnect(&self) -> Result<(), Error>
Disconnects the server end of a named pipe instance from a client process.
use compio_fs::named_pipe::{ClientOptions, ServerOptions};
use compio_io::AsyncWrite;
use windows_sys::Win32::Foundation::ERROR_PIPE_NOT_CONNECTED;
const PIPE_NAME: &str = r"\\.\pipe\compio-named-pipe-disconnect";
let server = ServerOptions::new().create(PIPE_NAME).unwrap();
let mut client = ClientOptions::new().open(PIPE_NAME).await.unwrap();
// Wait for a client to become connected.
server.connect().await.unwrap();
// Forcibly disconnect the client.
server.disconnect().unwrap();
// Write fails with an OS-specific error after client has been
// disconnected.
let e = client.write("ping").await.0.unwrap();
assert_eq!(e, 0);Trait Implementations§
Source§impl AsHandle for NamedPipeServer
impl AsHandle for NamedPipeServer
Source§fn as_handle(&self) -> BorrowedHandle<'_>
fn as_handle(&self) -> BorrowedHandle<'_>
Source§impl AsRawFd for NamedPipeServer
impl AsRawFd for NamedPipeServer
Source§impl AsRawHandle for NamedPipeServer
impl AsRawHandle for NamedPipeServer
Source§impl AsyncRead for &NamedPipeServer
impl AsyncRead for &NamedPipeServer
Source§impl AsyncRead for NamedPipeServer
impl AsyncRead for NamedPipeServer
Source§impl AsyncReadManaged for &NamedPipeServer
impl AsyncReadManaged for &NamedPipeServer
Source§type Buffer<'a> = BorrowedBuffer<'a>
type Buffer<'a> = BorrowedBuffer<'a>
Source§type BufferPool = BufferPool
type BufferPool = BufferPool
Source§async fn read_managed<'a>(
&mut self,
buffer_pool: &'a <&NamedPipeServer as AsyncReadManaged>::BufferPool,
len: usize,
) -> Result<<&NamedPipeServer as AsyncReadManaged>::Buffer<'a>, Error>
async fn read_managed<'a>( &mut self, buffer_pool: &'a <&NamedPipeServer as AsyncReadManaged>::BufferPool, len: usize, ) -> Result<<&NamedPipeServer as AsyncReadManaged>::Buffer<'a>, Error>
Source§impl AsyncReadManaged for NamedPipeServer
impl AsyncReadManaged for NamedPipeServer
Source§type Buffer<'a> = BorrowedBuffer<'a>
type Buffer<'a> = BorrowedBuffer<'a>
Source§type BufferPool = BufferPool
type BufferPool = BufferPool
Source§async fn read_managed<'a>(
&mut self,
buffer_pool: &'a <NamedPipeServer as AsyncReadManaged>::BufferPool,
len: usize,
) -> Result<<NamedPipeServer as AsyncReadManaged>::Buffer<'a>, Error>
async fn read_managed<'a>( &mut self, buffer_pool: &'a <NamedPipeServer as AsyncReadManaged>::BufferPool, len: usize, ) -> Result<<NamedPipeServer as AsyncReadManaged>::Buffer<'a>, Error>
Source§impl AsyncWrite for &NamedPipeServer
impl AsyncWrite for &NamedPipeServer
Source§async fn flush(&mut self) -> Result<(), Error>
async fn flush(&mut self) -> Result<(), Error>
Source§async fn shutdown(&mut self) -> Result<(), Error>
async fn shutdown(&mut self) -> Result<(), Error>
Source§async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
write, except that it write bytes from a buffer implements
IoVectoredBuf into the source. Read moreSource§impl AsyncWrite for NamedPipeServer
impl AsyncWrite for NamedPipeServer
Source§async fn flush(&mut self) -> Result<(), Error>
async fn flush(&mut self) -> Result<(), Error>
Source§async fn shutdown(&mut self) -> Result<(), Error>
async fn shutdown(&mut self) -> Result<(), Error>
Source§async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
write, except that it write bytes from a buffer implements
IoVectoredBuf into the source. Read moreSource§impl Clone for NamedPipeServer
impl Clone for NamedPipeServer
Source§fn clone(&self) -> NamedPipeServer
fn clone(&self) -> NamedPipeServer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NamedPipeServer
impl Debug for NamedPipeServer
Source§impl FromRawHandle for NamedPipeServer
impl FromRawHandle for NamedPipeServer
Source§unsafe fn from_raw_handle(handle: *mut c_void) -> NamedPipeServer
unsafe fn from_raw_handle(handle: *mut c_void) -> NamedPipeServer
Source§impl Splittable for &NamedPipeServer
impl Splittable for &NamedPipeServer
Source§type ReadHalf = NamedPipeServer
type ReadHalf = NamedPipeServer
AsyncRead or
AsyncReadAt.Source§type WriteHalf = NamedPipeServer
type WriteHalf = NamedPipeServer
AsyncWrite or
AsyncWriteAt.Source§fn split(
self,
) -> (<&NamedPipeServer as Splittable>::ReadHalf, <&NamedPipeServer as Splittable>::WriteHalf)
fn split( self, ) -> (<&NamedPipeServer as Splittable>::ReadHalf, <&NamedPipeServer as Splittable>::WriteHalf)
self and returns a tuple containing separate read and write
halves. Read moreSource§impl Splittable for NamedPipeServer
impl Splittable for NamedPipeServer
Source§type ReadHalf = NamedPipeServer
type ReadHalf = NamedPipeServer
AsyncRead or
AsyncReadAt.Source§type WriteHalf = NamedPipeServer
type WriteHalf = NamedPipeServer
AsyncWrite or
AsyncWriteAt.Source§fn split(
self,
) -> (<NamedPipeServer as Splittable>::ReadHalf, <NamedPipeServer as Splittable>::WriteHalf)
fn split( self, ) -> (<NamedPipeServer as Splittable>::ReadHalf, <NamedPipeServer as Splittable>::WriteHalf)
self and returns a tuple containing separate read and write
halves. Read moreSharedFd.Auto Trait Implementations§
impl Freeze for NamedPipeServer
impl RefUnwindSafe for NamedPipeServer
impl Send for NamedPipeServer
impl Sync for NamedPipeServer
impl Unpin for NamedPipeServer
impl UnwindSafe for NamedPipeServer
Blanket Implementations§
Source§impl<A> AsyncReadExt for A
impl<A> AsyncReadExt for A
Source§async fn append<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoBufMut,
async fn append<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoBufMut,
AsyncRead::read, but it appends data to the end of the
buffer; in other words, it read to the beginning of the uninitialized
area.Source§async fn read_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBufMut,
async fn read_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBufMut,
Source§async fn read_to_string(&mut self, buf: String) -> BufResult<usize, String>
async fn read_to_string(&mut self, buf: String) -> BufResult<usize, String>
String until underlying reader reaches EOF.Source§async fn read_to_end<A>(
&mut self,
buf: Vec<u8, A>,
) -> BufResult<usize, Vec<u8, A>>where
A: Allocator + 'static,
async fn read_to_end<A>(
&mut self,
buf: Vec<u8, A>,
) -> BufResult<usize, Vec<u8, A>>where
A: Allocator + 'static,
EOF.Source§async fn read_vectored_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBufMut,
async fn read_vectored_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBufMut,
Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§async fn read_u8(&mut self) -> Result<u8, Error>
async fn read_u8(&mut self) -> Result<u8, Error>
u8 from the underlying reader.Source§async fn read_u8_le(&mut self) -> Result<u8, Error>
async fn read_u8_le(&mut self) -> Result<u8, Error>
u8 from the underlying reader.Source§async fn read_u16(&mut self) -> Result<u16, Error>
async fn read_u16(&mut self) -> Result<u16, Error>
u16 from the underlying reader.Source§async fn read_u16_le(&mut self) -> Result<u16, Error>
async fn read_u16_le(&mut self) -> Result<u16, Error>
u16 from the underlying reader.Source§async fn read_u32(&mut self) -> Result<u32, Error>
async fn read_u32(&mut self) -> Result<u32, Error>
u32 from the underlying reader.Source§async fn read_u32_le(&mut self) -> Result<u32, Error>
async fn read_u32_le(&mut self) -> Result<u32, Error>
u32 from the underlying reader.Source§async fn read_u64(&mut self) -> Result<u64, Error>
async fn read_u64(&mut self) -> Result<u64, Error>
u64 from the underlying reader.Source§async fn read_u64_le(&mut self) -> Result<u64, Error>
async fn read_u64_le(&mut self) -> Result<u64, Error>
u64 from the underlying reader.Source§async fn read_u128(&mut self) -> Result<u128, Error>
async fn read_u128(&mut self) -> Result<u128, Error>
u128 from the underlying reader.Source§async fn read_u128_le(&mut self) -> Result<u128, Error>
async fn read_u128_le(&mut self) -> Result<u128, Error>
u128 from the underlying reader.Source§async fn read_i8(&mut self) -> Result<i8, Error>
async fn read_i8(&mut self) -> Result<i8, Error>
i8 from the underlying reader.Source§async fn read_i8_le(&mut self) -> Result<i8, Error>
async fn read_i8_le(&mut self) -> Result<i8, Error>
i8 from the underlying reader.Source§async fn read_i16(&mut self) -> Result<i16, Error>
async fn read_i16(&mut self) -> Result<i16, Error>
i16 from the underlying reader.Source§async fn read_i16_le(&mut self) -> Result<i16, Error>
async fn read_i16_le(&mut self) -> Result<i16, Error>
i16 from the underlying reader.Source§async fn read_i32(&mut self) -> Result<i32, Error>
async fn read_i32(&mut self) -> Result<i32, Error>
i32 from the underlying reader.Source§async fn read_i32_le(&mut self) -> Result<i32, Error>
async fn read_i32_le(&mut self) -> Result<i32, Error>
i32 from the underlying reader.Source§async fn read_i64(&mut self) -> Result<i64, Error>
async fn read_i64(&mut self) -> Result<i64, Error>
i64 from the underlying reader.Source§async fn read_i64_le(&mut self) -> Result<i64, Error>
async fn read_i64_le(&mut self) -> Result<i64, Error>
i64 from the underlying reader.Source§async fn read_i128(&mut self) -> Result<i128, Error>
async fn read_i128(&mut self) -> Result<i128, Error>
i128 from the underlying reader.Source§async fn read_i128_le(&mut self) -> Result<i128, Error>
async fn read_i128_le(&mut self) -> Result<i128, Error>
i128 from the underlying reader.Source§async fn read_f32(&mut self) -> Result<f32, Error>
async fn read_f32(&mut self) -> Result<f32, Error>
f32 from the underlying reader.Source§async fn read_f32_le(&mut self) -> Result<f32, Error>
async fn read_f32_le(&mut self) -> Result<f32, Error>
f32 from the underlying reader.Source§impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
AsyncWrite. Read moreSource§async fn write_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBuf,
async fn write_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBuf,
Source§async fn write_vectored_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBuf,
async fn write_vectored_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBuf,
AsyncWrite::write_vectored, except that it tries to write the entire
contents of the buffer into this writer.Source§async fn write_u8(&mut self, num: u8) -> Result<(), Error>
async fn write_u8(&mut self, num: u8) -> Result<(), Error>
u8 into the underlying writer.Source§async fn write_u8_le(&mut self, num: u8) -> Result<(), Error>
async fn write_u8_le(&mut self, num: u8) -> Result<(), Error>
u8 into the underlying writer.Source§async fn write_u16(&mut self, num: u16) -> Result<(), Error>
async fn write_u16(&mut self, num: u16) -> Result<(), Error>
u16 into the underlying writer.Source§async fn write_u16_le(&mut self, num: u16) -> Result<(), Error>
async fn write_u16_le(&mut self, num: u16) -> Result<(), Error>
u16 into the underlying writer.Source§async fn write_u32(&mut self, num: u32) -> Result<(), Error>
async fn write_u32(&mut self, num: u32) -> Result<(), Error>
u32 into the underlying writer.Source§async fn write_u32_le(&mut self, num: u32) -> Result<(), Error>
async fn write_u32_le(&mut self, num: u32) -> Result<(), Error>
u32 into the underlying writer.Source§async fn write_u64(&mut self, num: u64) -> Result<(), Error>
async fn write_u64(&mut self, num: u64) -> Result<(), Error>
u64 into the underlying writer.Source§async fn write_u64_le(&mut self, num: u64) -> Result<(), Error>
async fn write_u64_le(&mut self, num: u64) -> Result<(), Error>
u64 into the underlying writer.Source§async fn write_u128(&mut self, num: u128) -> Result<(), Error>
async fn write_u128(&mut self, num: u128) -> Result<(), Error>
u128 into the underlying writer.Source§async fn write_u128_le(&mut self, num: u128) -> Result<(), Error>
async fn write_u128_le(&mut self, num: u128) -> Result<(), Error>
u128 into the underlying writer.Source§async fn write_i8(&mut self, num: i8) -> Result<(), Error>
async fn write_i8(&mut self, num: i8) -> Result<(), Error>
i8 into the underlying writer.Source§async fn write_i8_le(&mut self, num: i8) -> Result<(), Error>
async fn write_i8_le(&mut self, num: i8) -> Result<(), Error>
i8 into the underlying writer.Source§async fn write_i16(&mut self, num: i16) -> Result<(), Error>
async fn write_i16(&mut self, num: i16) -> Result<(), Error>
i16 into the underlying writer.Source§async fn write_i16_le(&mut self, num: i16) -> Result<(), Error>
async fn write_i16_le(&mut self, num: i16) -> Result<(), Error>
i16 into the underlying writer.Source§async fn write_i32(&mut self, num: i32) -> Result<(), Error>
async fn write_i32(&mut self, num: i32) -> Result<(), Error>
i32 into the underlying writer.Source§async fn write_i32_le(&mut self, num: i32) -> Result<(), Error>
async fn write_i32_le(&mut self, num: i32) -> Result<(), Error>
i32 into the underlying writer.Source§async fn write_i64(&mut self, num: i64) -> Result<(), Error>
async fn write_i64(&mut self, num: i64) -> Result<(), Error>
i64 into the underlying writer.Source§async fn write_i64_le(&mut self, num: i64) -> Result<(), Error>
async fn write_i64_le(&mut self, num: i64) -> Result<(), Error>
i64 into the underlying writer.Source§async fn write_i128(&mut self, num: i128) -> Result<(), Error>
async fn write_i128(&mut self, num: i128) -> Result<(), Error>
i128 into the underlying writer.Source§async fn write_i128_le(&mut self, num: i128) -> Result<(), Error>
async fn write_i128_le(&mut self, num: i128) -> Result<(), Error>
i128 into the underlying writer.Source§async fn write_f32(&mut self, num: f32) -> Result<(), Error>
async fn write_f32(&mut self, num: f32) -> Result<(), Error>
f32 into the underlying writer.Source§async fn write_f32_le(&mut self, num: f32) -> Result<(), Error>
async fn write_f32_le(&mut self, num: f32) -> Result<(), Error>
f32 into the underlying writer.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more