pub enum TcpConnState {
Closed,
Connecting {
socket_handle: usize,
remote_ip: Ipv4Addr,
remote_port: u16,
local_port: u16,
start_tsc: TscTimestamp,
},
Established {
socket_handle: usize,
info: TcpConnectionInfo,
},
Closing {
socket_handle: usize,
start_tsc: TscTimestamp,
},
Error {
error: TcpError,
},
}Expand description
TCP connection state machine.
Manages non-blocking TCP connection establishment and closing. Does NOT handle data transfer - that’s done directly on the socket.
Variants§
Closed
Socket not connected
Connecting
Connection initiated, waiting for establishment
Fields
§
start_tsc: TscTimestampWhen connect started
Established
Connection established
Closing
Connection closing
Error
Error state
Implementations§
Source§impl TcpConnState
impl TcpConnState
Sourcepub fn initiate(
&mut self,
socket_handle: usize,
remote_ip: Ipv4Addr,
remote_port: u16,
local_port: u16,
now_tsc: u64,
)
pub fn initiate( &mut self, socket_handle: usize, remote_ip: Ipv4Addr, remote_port: u16, local_port: u16, now_tsc: u64, )
Initiate connection.
Called AFTER smoltcp’s socket.connect() has been called.
This just tracks the state - actual connect is done by smoltcp.
§Arguments
socket_handle: Socket handle from smoltcpremote_ip: Remote IP addressremote_port: Remote portlocal_port: Local port (0 for ephemeral)now_tsc: Current TSC timestamp
Sourcepub fn step(
&mut self,
socket_state: TcpSocketState,
now_tsc: u64,
timeout_ticks: u64,
) -> StepResult
pub fn step( &mut self, socket_state: TcpSocketState, now_tsc: u64, timeout_ticks: u64, ) -> StepResult
Step the state machine.
§Arguments
socket_state: Current TCP socket state from smoltcpnow_tsc: Current TSC valuetimeout_ticks: Connect/close timeout in TSC ticks
§Returns
Pending: Still connecting/closingDone: Connected (when Connecting) or Closed (when Closing)Timeout: Operation timed outFailed: Operation failed
Sourcepub fn close(&mut self, now_tsc: u64)
pub fn close(&mut self, now_tsc: u64)
Start graceful close.
Called AFTER smoltcp’s socket.close() has been called.
Sourcepub fn socket_handle(&self) -> Option<usize>
pub fn socket_handle(&self) -> Option<usize>
Get socket handle (if connecting or established).
Sourcepub fn connection_info(&self) -> Option<&TcpConnectionInfo>
pub fn connection_info(&self) -> Option<&TcpConnectionInfo>
Get connection info (if established).
Sourcepub fn is_established(&self) -> bool
pub fn is_established(&self) -> bool
Check if connection is established.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if terminal (established, closed, or error).
Trait Implementations§
Source§impl Debug for TcpConnState
impl Debug for TcpConnState
Auto Trait Implementations§
impl Freeze for TcpConnState
impl RefUnwindSafe for TcpConnState
impl Send for TcpConnState
impl Sync for TcpConnState
impl Unpin for TcpConnState
impl UnwindSafe for TcpConnState
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