pub struct Socket(/* private fields */);
Expand description
An object representing a Zircon socket
As essentially a subtype of Handle
, it can be freely interconverted.
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn create_stream() -> (Socket, Socket)
pub fn create_stream() -> (Socket, Socket)
Create a streaming socket, accessed through a pair of endpoints. Data written into one may be read from the other.
Wraps zx_socket_create.
§Panics
If the process’ job policy denies socket creation or the kernel reports no memory available to create a new socket.
Sourcepub fn create_datagram() -> (Socket, Socket)
pub fn create_datagram() -> (Socket, Socket)
Create a datagram socket, accessed through a pair of endpoints. Data written into one may be read from the other.
Wraps zx_socket_create.
§Panics
If the process’ job policy denies socket creation or the kernel reports no memory available to create a new socket.
Sourcepub fn write(&self, bytes: &[u8]) -> Result<usize, Status>
pub fn write(&self, bytes: &[u8]) -> Result<usize, Status>
Write the given bytes into the socket.
Return value (on success) is number of bytes actually written.
Wraps zx_socket_write.
Sourcepub unsafe fn write_raw(
&self,
bytes: *const u8,
len: usize,
) -> Result<usize, Status>
pub unsafe fn write_raw( &self, bytes: *const u8, len: usize, ) -> Result<usize, Status>
Write the given bytes into the socket.
Return value (on success) is number of bytes actually written.
§Safety
bytes
must be valid to read from for len
bytes.
Wraps zx_socket_write.
Sourcepub fn write_opts(
&self,
bytes: &[u8],
opts: SocketWriteOpts,
) -> Result<usize, Status>
pub fn write_opts( &self, bytes: &[u8], opts: SocketWriteOpts, ) -> Result<usize, Status>
Write the given bytes into the socket, with options.
Return value (on success) is number of bytes actually written.
Wraps zx_socket_write.
Sourcepub unsafe fn write_raw_opts(
&self,
bytes: *const u8,
len: usize,
opts: SocketWriteOpts,
) -> Result<usize, Status>
pub unsafe fn write_raw_opts( &self, bytes: *const u8, len: usize, opts: SocketWriteOpts, ) -> Result<usize, Status>
Write the given bytes into the socket, with options.
Return value (on success) is number of bytes actually written.
§Safety
bytes
must be valid to read from for len
bytes.
Wraps zx_socket_write.
Sourcepub fn read(&self, bytes: &mut [u8]) -> Result<usize, Status>
pub fn read(&self, bytes: &mut [u8]) -> Result<usize, Status>
Read the given bytes from the socket. Return value (on success) is number of bytes actually read.
Wraps zx_socket_read.
Sourcepub fn read_opts(
&self,
bytes: &mut [u8],
opts: SocketReadOpts,
) -> Result<usize, Status>
pub fn read_opts( &self, bytes: &mut [u8], opts: SocketReadOpts, ) -> Result<usize, Status>
Read the given bytes from the socket, with options. Return value (on success) is number of bytes actually read.
Wraps zx_socket_read.
Sourcepub unsafe fn read_raw(
&self,
bytes: *mut u8,
len: usize,
) -> Result<usize, Status>
pub unsafe fn read_raw( &self, bytes: *mut u8, len: usize, ) -> Result<usize, Status>
Read the given bytes from the socket.
Return value (on success) is number of bytes actually read.
§Safety
bytes
must be valid to write to for len
bytes.
Wraps zx_socket_read.
Sourcepub unsafe fn read_raw_opts(
&self,
bytes: *mut u8,
len: usize,
opts: SocketReadOpts,
) -> Result<usize, Status>
pub unsafe fn read_raw_opts( &self, bytes: *mut u8, len: usize, opts: SocketReadOpts, ) -> Result<usize, Status>
Read the given bytes from the socket, with options.
Return value (on success) is number of bytes actually read.
§Safety
bytes
must be valid to write to for len
bytes.
Wraps zx_socket_read.
Sourcepub fn read_uninit<'a>(
&self,
bytes: &'a mut [MaybeUninit<u8>],
) -> Result<&'a mut [u8], Status>
pub fn read_uninit<'a>( &self, bytes: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], Status>
Like Socket::read_uninit_opts
with default options.
Sourcepub fn read_uninit_opts<'a>(
&self,
bytes: &'a mut [MaybeUninit<u8>],
opts: SocketReadOpts,
) -> Result<&'a mut [u8], Status>
pub fn read_uninit_opts<'a>( &self, bytes: &'a mut [MaybeUninit<u8>], opts: SocketReadOpts, ) -> Result<&'a mut [u8], Status>
Same as Socket::read_opts, but reads into memory that might not be initialized, returning an initialized slice of bytes on success.
Sourcepub fn half_close(&self) -> Result<(), Status>
pub fn half_close(&self) -> Result<(), Status>
Close half of the socket, so attempts by the other side to write will fail.
Implements the ZX_SOCKET_DISPOSITION_WRITE_DISABLED
option of
zx_socket_set_disposition.
Sourcepub fn set_disposition(
&self,
disposition: Option<SocketWriteDisposition>,
disposition_peer: Option<SocketWriteDisposition>,
) -> Result<(), Status>
pub fn set_disposition( &self, disposition: Option<SocketWriteDisposition>, disposition_peer: Option<SocketWriteDisposition>, ) -> Result<(), Status>
Sets the disposition of write calls for a socket handle and its peer.
Wraps zx_socket_set_disposition.
Sourcepub fn outstanding_read_bytes(&self) -> Result<usize, Status>
pub fn outstanding_read_bytes(&self) -> Result<usize, Status>
Returns the number of bytes available on the socket.
Sourcepub fn info(&self) -> Result<SocketInfo, Status>
pub fn info(&self) -> Result<SocketInfo, Status>
Wraps the zx_object_get_info syscall for the ZX_INFO_SOCKET topic.
Trait Implementations§
Source§impl AsHandleRef for Socket
impl AsHandleRef for Socket
Source§fn as_handle_ref(&self) -> Unowned<'_, Handle>
fn as_handle_ref(&self) -> Unowned<'_, Handle>
object_wait_many
.