Struct netstack3_tcp::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 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

§

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>,

§

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>,

§

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

§

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

The type of state being accessed.
§

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>,