Struct Socket
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§
§impl Socket
impl Socket
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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§
§impl AsHandleRef for Socket
impl AsHandleRef for Socket
§fn as_handle_ref(&self) -> Unowned<'_, Handle>
fn as_handle_ref(&self) -> Unowned<'_, Handle>
object_wait_many.§fn raw_handle(&self) -> u32
fn raw_handle(&self) -> u32
§fn signal_handle(
&self,
clear_mask: Signals,
set_mask: Signals,
) -> Result<(), Status>
fn signal_handle( &self, clear_mask: Signals, set_mask: Signals, ) -> Result<(), Status>
§fn wait_handle(
&self,
signals: Signals,
deadline: Instant<MonotonicTimeline>,
) -> WaitResult
fn wait_handle( &self, signals: Signals, deadline: Instant<MonotonicTimeline>, ) -> WaitResult
§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>
§fn get_name(&self) -> Result<Name, Status>
fn get_name(&self) -> Result<Name, Status>
§fn set_name(&self, name: &Name) -> Result<(), Status>
fn set_name(&self, name: &Name) -> Result<(), Status>
§fn basic_info(&self) -> Result<HandleBasicInfo, Status>
fn basic_info(&self) -> Result<HandleBasicInfo, Status>
§fn count_info(&self) -> Result<HandleCountInfo, Status>
fn count_info(&self) -> Result<HandleCountInfo, Status>
Source§impl CompatFrom<Socket> for Socket
impl CompatFrom<Socket> for Socket
Source§fn compat_from(value: Socket) -> Socket
fn compat_from(value: Socket) -> Socket
value into a value of this type.Source§impl<E> Encode<WireSocket, E> for Socketwhere
E: HandleEncoder + ?Sized,
impl<E> Encode<WireSocket, E> for Socketwhere
E: HandleEncoder + ?Sized,
Source§fn encode(
self,
encoder: &mut E,
out: &mut MaybeUninit<WireSocket>,
constraint: <WireSocket as Constrained>::Constraint,
) -> Result<(), EncodeError>
fn encode( self, encoder: &mut E, out: &mut MaybeUninit<WireSocket>, constraint: <WireSocket as Constrained>::Constraint, ) -> Result<(), EncodeError>
Source§const COPY_OPTIMIZATION: CopyOptimization<Self, W> = _
const COPY_OPTIMIZATION: CopyOptimization<Self, W> = _
Source§impl<E> EncodeOption<WireOptionalSocket, E> for Socketwhere
E: HandleEncoder + ?Sized,
impl<E> EncodeOption<WireOptionalSocket, E> for Socketwhere
E: HandleEncoder + ?Sized,
Source§fn encode_option(
this: Option<Socket>,
encoder: &mut E,
out: &mut MaybeUninit<WireOptionalSocket>,
constraint: (),
) -> Result<(), EncodeError>
fn encode_option( this: Option<Socket>, encoder: &mut E, out: &mut MaybeUninit<WireOptionalSocket>, constraint: (), ) -> Result<(), EncodeError>
Source§impl FromWire<WireSocket> for Socket
impl FromWire<WireSocket> for Socket
Source§fn from_wire(wire: WireSocket) -> Socket
fn from_wire(wire: WireSocket) -> Socket
wire to this type.Source§const COPY_OPTIMIZATION: CopyOptimization<W, Self> = _
const COPY_OPTIMIZATION: CopyOptimization<W, Self> = _
Source§impl FromWireOption<WireOptionalSocket> for Socket
impl FromWireOption<WireOptionalSocket> for Socket
Source§fn from_wire_option(wire: WireOptionalSocket) -> Option<Socket>
fn from_wire_option(wire: WireOptionalSocket) -> Option<Socket>
wire to an option of this type.§impl HandleBased for Socket
impl HandleBased for Socket
§fn duplicate_handle(&self, rights: Rights) -> Result<Self, Status>
fn duplicate_handle(&self, rights: Rights) -> Result<Self, Status>
§fn replace_handle(self, rights: Rights) -> Result<Self, Status>
fn replace_handle(self, rights: Rights) -> Result<Self, Status>
§fn into_handle(self) -> Handle
fn into_handle(self) -> Handle
§fn from_handle(handle: Handle) -> Self
fn from_handle(handle: Handle) -> Self
§fn into_handle_based<H>(self) -> Hwhere
H: HandleBased,
fn into_handle_based<H>(self) -> Hwhere
H: HandleBased,
§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
§impl Ord for Socket
impl Ord for Socket
§impl PartialOrd for Socket
impl PartialOrd for Socket
§impl Peered for Socket
impl Peered for Socket
§fn signal_peer(
&self,
clear_mask: Signals,
set_mask: Signals,
) -> Result<(), Status>
fn signal_peer( &self, clear_mask: Signals, set_mask: Signals, ) -> Result<(), Status>
impl Eq for Socket
impl StructuralPartialEq for Socket
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> EncodableAsHandle for Twhere
T: HandleBased,
impl<T> EncodableAsHandle for Twhere
T: HandleBased,
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T, W> FromWireOption<WireBox<'_, W>> for Twhere
T: FromWire<W>,
impl<T, W> FromWireOption<WireBox<'_, W>> for Twhere
T: FromWire<W>,
Source§fn from_wire_option(wire: WireBox<'_, W>) -> Option<T>
fn from_wire_option(wire: WireBox<'_, W>) -> Option<T>
wire to an option of this type.Source§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
Source§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to Self