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 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
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,
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,
self
file descriptor. Read more