pub struct PolledSocket<T> { /* private fields */ }Expand description
A polled socket.
Implementations§
Source§impl<T: AsSockRef> PolledSocket<T>
impl<T: AsSockRef> PolledSocket<T>
Sourcepub fn new(driver: &(impl ?Sized + Driver), socket: T) -> Result<Self>
pub fn new(driver: &(impl ?Sized + Driver), socket: T) -> Result<Self>
Creates a new polled socket.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Extracts the inner socket.
Sourcepub fn poll_peek(
&mut self,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<usize>>
pub fn poll_peek( &mut self, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>
Polls for peeking at incoming data without consuming it.
On success, the peeked bytes are written to the start of buf and the
number of bytes peeked is returned. A return value of Ok(0) indicates
that the peer has closed the connection (or that buf was empty).
The peeked data remains in the socket’s receive buffer, so a subsequent read (or peek) will observe the same bytes.
Source§impl<T> PolledSocket<T>
impl<T> PolledSocket<T>
Source§impl<T> PolledSocket<T>
impl<T> PolledSocket<T>
Sourcepub fn poll_io<F, R>(
&mut self,
cx: &mut Context<'_>,
slot: InterestSlot,
events: PollEvents,
f: F,
) -> Poll<Result<R>>
pub fn poll_io<F, R>( &mut self, cx: &mut Context<'_>, slot: InterestSlot, events: PollEvents, f: F, ) -> Poll<Result<R>>
Calls nonblocking operation f when the socket has least one event in
events ready.
Uses interest slot slot to allow multiple concurrent operations.
If f returns Err(err) with err.kind() == io::ErrorKind::WouldBlock, then this re-polls the socket for readiness
and returns Poll::Pending.
Source§impl<T> PolledSocket<T>
impl<T> PolledSocket<T>
Sourcepub fn split(self) -> (ReadHalf<T>, WriteHalf<T>)
pub fn split(self) -> (ReadHalf<T>, WriteHalf<T>)
Splits the socket into a read and write half that can be used concurrently.
This is more flexible and efficient than
[futures::io::AsyncReadExt::split], since it avoids holding a lock
while calling into the kernel, and it provides access to the underlying
socket for more advanced operations.
Source§impl PolledSocket<Socket>
impl PolledSocket<Socket>
Source§impl PolledSocket<TcpStream>
impl PolledSocket<TcpStream>
Sourcepub async fn connect_tcp(
driver: &(impl ?Sized + Driver),
addr: SocketAddr,
) -> Result<Self>
pub async fn connect_tcp( driver: &(impl ?Sized + Driver), addr: SocketAddr, ) -> Result<Self>
Creates a new connected TCP stream socket.
Source§impl PolledSocket<Socket>
impl PolledSocket<Socket>
Trait Implementations§
Source§impl<T: AsSockRef + Read> AsyncRead for PolledSocket<T>
impl<T: AsSockRef + Read> AsyncRead for PolledSocket<T>
Source§impl<T: AsSockRef + Write> AsyncWrite for PolledSocket<T>
impl<T: AsSockRef + Write> AsyncWrite for PolledSocket<T>
Source§fn 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>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§impl<T: AsSockRef> PollReady for PolledSocket<T>
impl<T: AsSockRef> PollReady for PolledSocket<T>
Source§fn poll_ready(
&mut self,
cx: &mut Context<'_>,
events: PollEvents,
) -> Poll<PollEvents>
fn poll_ready( &mut self, cx: &mut Context<'_>, events: PollEvents, ) -> Poll<PollEvents>
Auto Trait Implementations§
impl<T> !Freeze for PolledSocket<T>
impl<T> !RefUnwindSafe for PolledSocket<T>
impl<T> Send for PolledSocket<T>where
T: Send,
impl<T> Sync for PolledSocket<T>where
T: Sync,
impl<T> Unpin for PolledSocket<T>where
T: Unpin,
impl<T> UnsafeUnpin for PolledSocket<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for PolledSocket<T>
Blanket Implementations§
§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
§fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
buf in asynchronous
manner, returning a future type. Read more§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
AsyncRead into bufs using vectored
IO operations. Read more§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf,
returning an error if end of file (EOF) is hit sooner. Read more§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
AsyncRead. Read more§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
AsyncRead. Read more§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
AsyncWrite. Read more§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
AsyncWrite.§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
buf into the object. Read more§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
bufs into the object using vectored
IO operations. Read more