Struct fidl::handle::fuchsia_handles::Socket
source · 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
.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 HandleBased for Socket
impl HandleBased for Socket
source§fn duplicate_handle(&self, rights: Rights) -> Result<Self, Status>
fn duplicate_handle(&self, rights: Rights) -> Result<Self, Status>
source§fn replace_handle(self, rights: Rights) -> Result<Self, Status>
fn replace_handle(self, rights: Rights) -> Result<Self, Status>
source§fn into_handle(self) -> Handle
fn into_handle(self) -> Handle
source§fn from_handle(handle: Handle) -> Self
fn from_handle(handle: Handle) -> Self
source§fn into_handle_based<H>(self) -> Hwhere
H: HandleBased,
fn into_handle_based<H>(self) -> Hwhere
H: HandleBased,
source§fn from_handle_based<H>(h: H) -> Selfwhere
H: HandleBased,
fn from_handle_based<H>(h: H) -> Selfwhere
H: HandleBased,
fn is_invalid_handle(&self) -> bool
source§impl Ord for Socket
impl Ord for Socket
source§impl PartialEq for Socket
impl PartialEq for Socket
source§impl PartialOrd for Socket
impl PartialOrd for Socket
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more