Skip to main content

## SocketState

# Enum SocketState

Source

    enum SocketState {
        Initial,
        Bound(SocketAddr),
        Listening(TcpListener),
        Connecting(TcpStream),
        Connected(TcpStream),
    }

## Variants§

§

### Initial

No syscall after `socket` has been made.

§

### Bound(SocketAddr)

The `bind` syscall has been called on the socket. This is only reachable from the `SocketState::Initial` state.

§

### Listening(TcpListener)

The `listen` syscall has been called on the socket. This is only reachable from the `SocketState::Bound` state.

§

### 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.

## Implementations§

Source§

### impl SocketState

Source

#### pub fn try_set_connected(&mut self) -> Result<(), SocketIoError>

If the socket is currently in `SocketState::Connecting`, try to ensure that the connection is established by first checking that [`TcpStream::take_error`] doesn’t return an error and then by checking that [`TcpStream::peer_addr`] returns the address of the connected peer.

If the connection is established or the socket is in any other state, `Ok` is returned.

Important: On Windows hosts this function can only be used to ensure a socket is connected after a [`Interest::WRITABLE`] event was received.

## 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§

§

### impl Freeze for SocketState

§

### impl RefUnwindSafe for SocketState

§

### impl Send for SocketState

§

### impl Sync for SocketState

§

### impl Unpin for SocketState

§

### impl UnsafeUnpin for SocketState

§

### impl UnwindSafe for SocketState

## 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 = 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.
§

### impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

#### fn vzip(self) -> V

## 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: 32 bytes

Size for each variant:

- `Initial`: 0 bytes
- `Bound`: 32 bytes
- `Listening`: 8 bytes
- `Connecting`: 8 bytes
- `Connected`: 8 bytes