pub struct Socket(/* private fields */);
Expand description
An I/O object representing a Socket
.
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn from_socket(socket: Socket) -> Self
pub fn from_socket(socket: Socket) -> Self
Create a new Socket
from a previously-created zx::Socket
.
§Panics
If called outside the context of an active async executor.
Sourcepub fn into_zx_socket(self) -> Socket
pub fn into_zx_socket(self) -> Socket
Consumes self
and returns the underlying zx::Socket
.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true if the socket received the OBJECT_PEER_CLOSED
signal.
Sourcepub fn on_closed(&self) -> OnSignalsRef<'_>
pub fn on_closed(&self) -> OnSignalsRef<'_>
Returns a future that completes when the socket received the OBJECT_PEER_CLOSED
signal.
Sourcepub fn poll_read_ref(
&self,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<usize, Status>>
pub fn poll_read_ref( &self, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize, Status>>
Attempt to read from the socket, registering for wakeup if the socket doesn’t have any
contents available. Used internally in the AsyncRead
implementation, exposed for users
who know the concrete type they’re using and don’t want to pin the socket.
Sourcepub fn poll_write_ref(
&self,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Status>>
pub fn poll_write_ref( &self, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Status>>
Attempt to write into the socket, registering for wakeup if the socket is not ready. Used
internally in the AsyncWrite
implementation, exposed for users who know the concrete type
they’re using and don’t want to pin the socket.
Sourcepub fn poll_datagram(
&self,
cx: &mut Context<'_>,
out: &mut Vec<u8>,
) -> Poll<Result<usize, Status>>
pub fn poll_datagram( &self, cx: &mut Context<'_>, out: &mut Vec<u8>, ) -> Poll<Result<usize, Status>>
Polls for the next data on the socket, appending it to the end of |out| if it has arrived. Not very useful for a non-datagram socket as it will return all available data on the socket.
Sourcepub async fn read_datagram<'a>(
&'a self,
out: &'a mut Vec<u8>,
) -> Result<usize, Status>
pub async fn read_datagram<'a>( &'a self, out: &'a mut Vec<u8>, ) -> Result<usize, Status>
Reads the next datagram that becomes available onto the end of |out|. Note: Using this multiple times concurrently is an error and the first one will never complete.
Sourcepub fn as_datagram_stream<'a>(&'a self) -> DatagramStream<&'a Self>
pub fn as_datagram_stream<'a>(&'a self) -> DatagramStream<&'a Self>
Use this socket as a stream of Result<Vec<u8>, zx::Status>
datagrams.
Note: multiple concurrent streams from the same socket are not supported.
Sourcepub fn into_datagram_stream(self) -> DatagramStream<Self>
pub fn into_datagram_stream(self) -> DatagramStream<Self>
Convert this socket into a stream of Result<Vec<u8>, zx::Status>
datagrams.
Trait Implementations§
Source§impl AsHandleRef for Socket
impl AsHandleRef for Socket
Source§fn as_handle_ref(&self) -> HandleRef<'_>
fn as_handle_ref(&self) -> HandleRef<'_>
object_wait_many
.Source§fn raw_handle(&self) -> u32
fn raw_handle(&self) -> u32
Source§fn signal_handle(
&self,
clear_mask: Signals,
set_mask: Signals,
) -> Result<(), Status>
fn signal_handle( &self, clear_mask: Signals, set_mask: Signals, ) -> Result<(), Status>
Source§fn wait_handle(
&self,
signals: Signals,
deadline: Instant<MonotonicTimeline>,
) -> Result<Signals, Status>
fn wait_handle( &self, signals: Signals, deadline: Instant<MonotonicTimeline>, ) -> Result<Signals, Status>
Source§fn wait_async_handle(
&self,
port: &Port,
key: u64,
signals: Signals,
options: WaitAsyncOpts,
) -> Result<(), Status>
fn wait_async_handle( &self, port: &Port, key: u64, signals: Signals, options: WaitAsyncOpts, ) -> Result<(), Status>
Source§fn get_name(&self) -> Result<Name, Status>
fn get_name(&self) -> Result<Name, Status>
Source§fn set_name(&self, name: &Name) -> Result<(), Status>
fn set_name(&self, name: &Name) -> Result<(), Status>
Source§fn basic_info(&self) -> Result<HandleBasicInfo, Status>
fn basic_info(&self) -> Result<HandleBasicInfo, Status>
Source§fn count_info(&self) -> Result<HandleCountInfo, Status>
fn count_info(&self) -> Result<HandleCountInfo, Status>
Source§impl<'a> AsyncRead for &'a Socket
impl<'a> AsyncRead for &'a Socket
Source§impl AsyncRead for Socket
impl AsyncRead for Socket
Source§impl<'a> AsyncWrite for &'a Socket
impl<'a> AsyncWrite for &'a Socket
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>, _: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>
Source§impl AsyncWrite for Socket
impl AsyncWrite for Socket
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>, _: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>
Source§impl ReadableHandle for Socket
impl ReadableHandle for Socket
Source§fn poll_readable(
&self,
cx: &mut Context<'_>,
) -> Poll<Result<ReadableState, Status>>
fn poll_readable( &self, cx: &mut Context<'_>, ) -> Poll<Result<ReadableState, Status>>
Ready
with the readable
state. If the implementor returns Pending, it should first ensure that
need_readable
is called. Read moreSource§fn need_readable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>
fn need_readable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>
OBJECT_READABLE
or OBJECT_PEER_CLOSED
signal. This can return
Poll::Ready if the object has already been signaled in which case the
waker will not be woken and it is the caller’s responsibility to not
lose the signal.Source§impl WritableHandle for Socket
impl WritableHandle for Socket
Source§fn poll_writable(
&self,
cx: &mut Context<'_>,
) -> Poll<Result<WritableState, Status>>
fn poll_writable( &self, cx: &mut Context<'_>, ) -> Poll<Result<WritableState, Status>>
Ready
with the writable
state. If the implementor returns Pending, it should first ensure that
need_writable
is called. Read moreSource§fn need_writable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>
fn need_writable(&self, cx: &mut Context<'_>) -> Poll<Result<(), Status>>
OBJECT_WRITABLE
or OBJECT_PEER_CLOSED
signal. This can return
Poll::Ready if the object has already been signaled in which case the
waker will not be woken and it is the caller’s responsibility to not
lose the signal.Auto Trait Implementations§
impl Freeze for Socket
impl !RefUnwindSafe for Socket
impl Send for Socket
impl Sync for Socket
impl Unpin for Socket
impl !UnwindSafe for Socket
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