Struct tokio::net::windows::named_pipe::NamedPipeClient
source · [−]pub struct NamedPipeClient { /* private fields */ }
Expand description
A Windows named pipe client.
Constructed using ClientOptions::open
.
Connecting a client correctly involves a few steps. When connecting through
ClientOptions::open
, it might error indicating one of two things:
std::io::ErrorKind::NotFound
- There is no server available.ERROR_PIPE_BUSY
- There is a server available, but it is busy. Sleep for a while and try again.
So a correctly implemented client looks like this:
use std::time::Duration;
use tokio::net::windows::named_pipe::ClientOptions;
use tokio::time;
use winapi::shared::winerror;
const PIPE_NAME: &str = r"\\.\pipe\named-pipe-idiomatic-client";
let client = loop {
match ClientOptions::new().open(PIPE_NAME) {
Ok(client) => break client,
Err(e) if e.raw_os_error() == Some(winerror::ERROR_PIPE_BUSY as i32) => (),
Err(e) => return Err(e),
}
time::sleep(Duration::from_millis(50)).await;
};
/* use the connected client */
Implementations
sourceimpl NamedPipeClient
impl NamedPipeClient
sourcepub unsafe fn from_raw_handle(handle: RawHandle) -> Result<Self>
pub unsafe fn from_raw_handle(handle: RawHandle) -> Result<Self>
Construct a new named pipe client from the specified raw handle.
This function will consume ownership of the handle given, passing responsibility for closing the handle to the returned object.
This function is also unsafe as the primitives currently returned have the contract that they are the sole owner of the file descriptor they are wrapping. Usage of this function could accidentally allow violating this contract which can cause memory unsafety in code that relies on it being true.
Errors
This errors if called outside of a Tokio Runtime, or in a runtime that has not enabled I/O, or if any OS-specific I/O errors occur.
sourcepub fn info(&self) -> Result<PipeInfo>
pub fn info(&self) -> Result<PipeInfo>
Retrieves information about the named pipe the client is associated with.
use tokio::net::windows::named_pipe::{ClientOptions, PipeEnd, PipeMode};
const PIPE_NAME: &str = r"\\.\pipe\tokio-named-pipe-client-info";
let client = ClientOptions::new()
.open(PIPE_NAME)?;
let client_info = client.info()?;
assert_eq!(client_info.end, PipeEnd::Client);
assert_eq!(client_info.mode, PipeMode::Message);
assert_eq!(client_info.max_instances, 5);
Trait Implementations
sourceimpl AsRawHandle for NamedPipeClient
impl AsRawHandle for NamedPipeClient
sourcefn as_raw_handle(&self) -> RawHandle
fn as_raw_handle(&self) -> RawHandle
Extracts the raw handle. Read more
sourceimpl AsyncRead for NamedPipeClient
impl AsyncRead for NamedPipeClient
sourceimpl AsyncWrite for NamedPipeClient
impl AsyncWrite for NamedPipeClient
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize>>
Like poll_write
, except that it writes from a slice of buffers. Read more
sourcefn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
sourcefn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
Determines if this writer has an efficient poll_write_vectored
implementation. Read more
Auto Trait Implementations
impl !RefUnwindSafe for NamedPipeClient
impl Send for NamedPipeClient
impl Sync for NamedPipeClient
impl Unpin for NamedPipeClient
impl !UnwindSafe for NamedPipeClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more