netstack3_tcp

Struct TcpApi

Source
pub struct TcpApi<I: Ip, C>(/* private fields */);
Expand description

The TCP socket API.

Implementations§

Source§

impl<I: Ip, C> TcpApi<I, C>

Source

pub fn new(ctx: C) -> Self

Creates a new TcpApi from ctx.

Source§

impl<I, C> TcpApi<I, C>

Source

pub fn create( &mut self, socket_extra: <C::BindingsContext as TcpBindingsTypes>::ListenerNotifierOrProvidedBuffers, ) -> TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>

Creates a new socket in unbound state.

Source

pub fn bind( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, addr: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, port: Option<NonZeroU16>, ) -> Result<(), BindError>

Binds an unbound socket to a local socket address.

Requests that the given socket be bound to the local address, if one is provided; otherwise to all addresses. If port is specified (is Some), the socket will be bound to that port. Otherwise a port will be selected to not conflict with existing bound or connected sockets.

Source

pub fn listen( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, backlog: NonZeroUsize, ) -> Result<(), ListenError>

Listens on an already bound socket.

Source

pub fn accept( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Result<(TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, SocketAddr<I::Addr, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, <C::BindingsContext as TcpBindingsTypes>::ReturnedBuffers), AcceptError>

Accepts an established socket from the queue of a listener socket.

Source

pub fn connect( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, remote_ip: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, remote_port: NonZeroU16, ) -> Result<(), ConnectError>

Connects a socket to a remote address.

When the method returns, the connection is not guaranteed to be established. It is up to the caller (Bindings) to determine when the connection has been established. Bindings are free to use anything available on the platform to check, for instance, signals.

Source

pub fn close( &mut self, id: TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, )

Closes a socket.

Source

pub fn shutdown( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, shutdown_type: ShutdownType, ) -> Result<bool, NoConnection>

Shuts down a socket.

For a connection, calling this function signals the other side of the connection that we will not be sending anything over the connection; The connection will be removed from the socketmap if the state moves to the Closed state.

For a Listener, calling this function brings it back to bound state and shutdowns all the connection that is currently ready to be accepted.

Returns Err(NoConnection) if the shutdown option does not apply. Otherwise, Whether a connection has been shutdown is returned, i.e., if the socket was a listener, the operation will succeed but false will be returned.

Source

pub fn on_receive_buffer_read( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, )

Polls the state machine after data is dequeued from the receive buffer.

Possibly sends a window update to the peer if enough data has been read from the buffer and we suspect that the peer is in SWS avoidance.

This does nothing for a disconnected socket.

Source

pub fn set_device( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, new_device: Option<<C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, ) -> Result<(), SetDeviceError>

Sets the device on a socket.

Passing None clears the bound device.

Source

pub fn get_info( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> SocketInfo<I::Addr, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Get information for a TCP socket.

Source

pub fn do_send( &mut self, conn_id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, )

Call this function whenever a socket can push out more data. That means either:

  • A retransmission timer fires.
  • An ack received from peer so that our send window is enlarged.
  • The user puts data into the buffer and we are notified.
Source

pub fn with_socket_options_mut<R, F: FnOnce(&mut SocketOptions) -> R>( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, f: F, ) -> R

Access options mutably for a TCP socket.

Source

pub fn with_socket_options<R, F: FnOnce(&SocketOptions) -> R>( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, f: F, ) -> R

Access socket options immutably for a TCP socket

Source

pub fn set_send_buffer_size( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, size: usize, )

Set the size of the send buffer for this socket and future derived sockets.

Source

pub fn send_buffer_size( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Option<usize>

Get the size of the send buffer for this socket and future derived sockets.

Source

pub fn set_receive_buffer_size( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, size: usize, )

Set the size of the send buffer for this socket and future derived sockets.

Source

pub fn receive_buffer_size( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Option<usize>

Get the size of the receive buffer for this socket and future derived sockets.

Source

pub fn set_reuseaddr( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, reuse: bool, ) -> Result<(), SetReuseAddrError>

Sets the POSIX SO_REUSEADDR socket option on a socket.

Source

pub fn reuseaddr( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> bool

Gets the POSIX SO_REUSEADDR socket option on a socket.

Source

pub fn dual_stack_enabled( &mut self, id: &TcpSocketId<I, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, C::BindingsContext>, ) -> Result<bool, NotDualStackCapableError>

Gets the dual_stack_enabled option value.

Source

pub fn set_mark( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, domain: MarkDomain, mark: Mark, )

Sets the socket mark for the socket domain.

Source

pub fn get_mark( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, domain: MarkDomain, ) -> Mark

Gets the socket mark for the socket domain.

Source

pub fn set_dual_stack_enabled( &mut self, id: &TcpSocketId<I, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, C::BindingsContext>, value: bool, ) -> Result<(), SetDualStackEnabledError>

Sets the dual_stack_enabled option value.

Source

pub fn get_socket_error( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Option<ConnectionError>

Gets the last error on the connection.

Source

pub fn get_original_destination( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Result<(SpecifiedAddr<I::Addr>, NonZeroU16), OriginalDestinationError>

Gets the original destination address for the socket, if it is connected and has a destination in the specified stack.

Note that this always returns the original destination in the IP stack in which the socket is; for example, for a dual-stack IPv6 socket that is connected to an IPv4 address, this will return the IPv4-mapped IPv6 version of that address.

Source

pub fn inspect<N>(&mut self, inspector: &mut N)

Provides access to shared and per-socket TCP stats via a visitor.

Source

pub fn with_send_buffer<R, F: FnOnce(&mut <C::BindingsContext as TcpBindingsTypes>::SendBuffer) -> R>( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, f: F, ) -> Option<R>

Calls the callback with mutable access to the send buffer, if one is instantiated.

If no buffer is instantiated returns None.

Source

pub fn with_receive_buffer<R, F: FnOnce(&mut <C::BindingsContext as TcpBindingsTypes>::ReceiveBuffer) -> R>( &mut self, id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, f: F, ) -> Option<R>

Calls the callback with mutable access to the receive buffer, if one is instantiated.

If no buffer is instantiated returns None.

Auto Trait Implementations§

§

impl<I, C> Freeze for TcpApi<I, C>
where C: Freeze,

§

impl<I, C> RefUnwindSafe for TcpApi<I, C>

§

impl<I, C> Send for TcpApi<I, C>
where C: Send,

§

impl<I, C> Sync for TcpApi<I, C>
where C: Sync,

§

impl<I, C> Unpin for TcpApi<I, C>
where C: Unpin, I: Unpin,

§

impl<I, C> UnwindSafe for TcpApi<I, C>
where C: UnwindSafe, I: UnwindSafe,

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<CC, BC, Meta> RecvFrameContext<Meta, BC> for CC
where Meta: ReceivableFrameMeta<CC, BC>,

Source§

fn receive_frame<B>(&mut self, bindings_ctx: &mut BC, metadata: Meta, frame: B)
where B: BufferMut + Debug,

Receive a frame. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CC
where Meta: SendableFrameMeta<CC, BC>,

Source§

fn send_frame<S>( &mut self, bindings_ctx: &mut BC, metadata: Meta, frame: S, ) -> Result<(), ErrorAndSerializer<SendFrameErrorReason, S>>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Send a frame. Read more
Source§

impl<Id, CC, BC> TimerHandler<BC, Id> for CC
where BC: TimerBindingsTypes, Id: HandleableTimer<CC, BC>,

Source§

fn handle_timer( &mut self, bindings_ctx: &mut BC, dispatch: Id, timer: <BC as TimerBindingsTypes>::UniqueTimerId, )

Handle a timer firing. Read more
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.
Source§

impl<L, T> UnlockedAccess<L> for T

Source§

type Data = <L as UnlockedAccessMarkerFor<T>>::Data

The type of state being accessed.
Source§

type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data where T: 'l

A guard providing read access to the data.
Source§

fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>

How to access the state.
§

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

§

fn vzip(self) -> V

Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,