morpheus_network::state::tcp

Enum TcpConnState

Source
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

§socket_handle: usize

Socket handle (opaque, passed to smoltcp)

§remote_ip: Ipv4Addr

Remote address

§remote_port: u16

Remote port

§local_port: u16

Local port (for reference)

§start_tsc: TscTimestamp

When connect started

§

Established

Connection established

Fields

§socket_handle: usize

Socket handle

§info: TcpConnectionInfo

Connection info

§

Closing

Connection closing

Fields

§socket_handle: usize

Socket handle

§start_tsc: TscTimestamp

When close started

§

Error

Error state

Fields

§error: TcpError

Error details

Implementations§

Source§

impl TcpConnState

Source

pub fn new() -> Self

Create new TCP state machine in closed state.

Source

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 smoltcp
  • remote_ip: Remote IP address
  • remote_port: Remote port
  • local_port: Local port (0 for ephemeral)
  • now_tsc: Current TSC timestamp
Source

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 smoltcp
  • now_tsc: Current TSC value
  • timeout_ticks: Connect/close timeout in TSC ticks
§Returns
  • Pending: Still connecting/closing
  • Done: Connected (when Connecting) or Closed (when Closing)
  • Timeout: Operation timed out
  • Failed: Operation failed
Source

pub fn close(&mut self, now_tsc: u64)

Start graceful close.

Called AFTER smoltcp’s socket.close() has been called.

Source

pub fn abort(&mut self)

Abort connection immediately.

Source

pub fn fail(&mut self, error: TcpError)

Mark as failed with error.

Source

pub fn socket_handle(&self) -> Option<usize>

Get socket handle (if connecting or established).

Source

pub fn connection_info(&self) -> Option<&TcpConnectionInfo>

Get connection info (if established).

Source

pub fn error(&self) -> Option<TcpError>

Get error (if failed).

Source

pub fn is_established(&self) -> bool

Check if connection is established.

Source

pub fn is_closed(&self) -> bool

Check if closed (initial or after close).

Source

pub fn is_error(&self) -> bool

Check if in error state.

Source

pub fn is_terminal(&self) -> bool

Check if terminal (established, closed, or error).

Trait Implementations§

Source§

impl Debug for TcpConnState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TcpConnState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.