pub struct TcpSocket { /* private fields */ }
Expand description
A TCP socket resource.
The socket can be in one of the following states:
unbound
bind-in-progress
bound
(See note below)listen-in-progress
listening
connect-in-progress
connected
closed
See https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md for more information.
Note: Except where explicitly mentioned, whenever this documentation uses
the term “bound” without backticks it actually means: in the bound
state or higher.
(i.e. bound
, listen-in-progress
, listening
, connect-in-progress
or connected
)
In addition to the general error codes documented on the
network::error-code
type, TCP socket methods may always return
error(invalid-state)
when in the closed
state.
A host TCP socket, plus associated bookkeeping.
Implementations§
source§impl TcpSocket
impl TcpSocket
sourcepub fn new(family: AddressFamily) -> Result<Self>
pub fn new(family: AddressFamily) -> Result<Self>
Create a new socket in the given family.
source§impl TcpSocket
impl TcpSocket
pub fn start_bind(&mut self, local_address: SocketAddr) -> Result<()>
pub fn finish_bind(&mut self) -> SocketResult<()>
pub fn start_connect(&mut self, remote_address: SocketAddr) -> SocketResult<()>
pub fn finish_connect(&mut self) -> SocketResult<(InputStream, OutputStream)>
pub fn start_listen(&mut self) -> SocketResult<()>
pub fn finish_listen(&mut self) -> SocketResult<()>
pub fn accept(&mut self) -> SocketResult<(Self, InputStream, OutputStream)>
pub fn local_address(&self) -> SocketResult<SocketAddr>
pub fn remote_address(&self) -> SocketResult<SocketAddr>
pub fn is_listening(&self) -> bool
pub fn address_family(&self) -> SocketAddressFamily
pub fn set_listen_backlog_size(&mut self, value: u32) -> SocketResult<()>
pub fn keep_alive_enabled(&self) -> SocketResult<bool>
pub fn set_keep_alive_enabled(&self, value: bool) -> SocketResult<()>
pub fn keep_alive_idle_time(&self) -> SocketResult<Duration>
pub fn set_keep_alive_idle_time( &mut self, duration: Duration, ) -> SocketResult<()>
pub fn keep_alive_interval(&self) -> SocketResult<Duration>
pub fn set_keep_alive_interval(&self, duration: Duration) -> SocketResult<()>
pub fn keep_alive_count(&self) -> SocketResult<u32>
pub fn set_keep_alive_count(&self, value: u32) -> SocketResult<()>
pub fn hop_limit(&self) -> SocketResult<u8>
pub fn set_hop_limit(&mut self, value: u8) -> SocketResult<()>
pub fn receive_buffer_size(&self) -> SocketResult<usize>
pub fn set_receive_buffer_size(&mut self, value: usize) -> SocketResult<()>
pub fn send_buffer_size(&self) -> SocketResult<usize>
pub fn set_send_buffer_size(&mut self, value: usize) -> SocketResult<()>
pub fn shutdown(&self, how: Shutdown) -> SocketResult<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TcpSocket
impl !RefUnwindSafe for TcpSocket
impl Send for TcpSocket
impl !Sync for TcpSocket
impl Unpin for TcpSocket
impl !UnwindSafe for TcpSocket
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
Mutably borrows from an owned value. Read more
source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self
file descriptor.source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
Set the “status” flags for the
self
file descriptor. Read moresource§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more