Skip to main content

SocketState

Enum SocketState 

Source
enum SocketState {
    Initial(Socket),
    Listening(TcpListener),
    Connecting(TcpStream),
    Connected(TcpStream),
    ConnectionFailed(TcpStream),
    None,
}

Variants§

§

Initial(Socket)

No syscall after socket has been made.

§

Listening(TcpListener)

The listen syscall has been called on the socket. This is reachable from the SocketState::Initial and the SocketState::Listening states.

§

Connecting(TcpStream)

The connect syscall has been called and we weren’t yet able to ensure the connection is established. This is only reachable from the SocketState::Initial state.

§

Connected(TcpStream)

The connect syscall has been called on the socket and we ensured that the connection is established, or the socket was created by the accept syscall. For a socket created using the connect syscall, this is only reachable from the SocketState::Connecting state.

§

ConnectionFailed(TcpStream)

The SO_ERROR socket option has been set after calling the connect syscall, indicating that the connection attempt failed. By the POSIX specification, a socket is is an unspecified state after a failed connection attempt and thus nothing (except destroying the socket) should be supported when a socket is in this state.

§

None

The socket state machine is transitioning between two states which contain an underlying host socket. This state is never observable, it’s only needed as a placeholder state to safely acquire ownership of the underlying host socket.

Implementations§

Source§

impl SocketState

Source

fn as_socket_ref<'a>(&'a self) -> SockRef<'a>

View the underlying host socket as a [socket2::SockRef].

Note: Potentially blocking operations need to be performed on the underlying [TcpStream] and [TcpListener] as it would break the mio poll on Windows hosts when performed directly on the [socket2::SockRef].

Trait Implementations§

Source§

impl Debug for SocketState

Source§

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

Formats the value using the given formatter. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes

Size for each variant:

  • Initial: 4 bytes
  • Listening: 4 bytes
  • Connecting: 4 bytes
  • Connected: 4 bytes
  • ConnectionFailed: 4 bytes
  • None: 0 bytes