pub struct TcpApi<I: Ip, C>(/* private fields */);
Expand description
The TCP socket API.
Implementations§
Source§impl<I, C> TcpApi<I, C>where
I: DualStackIpExt,
C: ContextPair,
C::CoreContext: TcpContext<I, C::BindingsContext> + CounterContext<TcpCounters<I>>,
C::BindingsContext: TcpBindingsContext,
impl<I, C> TcpApi<I, C>where
I: DualStackIpExt,
C: ContextPair,
C::CoreContext: TcpContext<I, C::BindingsContext> + CounterContext<TcpCounters<I>>,
C::BindingsContext: TcpBindingsContext,
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn listen(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
backlog: NonZeroUsize,
) -> Result<(), ListenError>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn close(
&mut self,
id: TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
)
pub fn close( &mut self, id: TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, )
Closes a socket.
Sourcepub 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>
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.
Sourcepub fn on_receive_buffer_read(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
)
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn do_send(
&mut self,
conn_id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
)
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.
Sourcepub 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
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.
Sourcepub 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
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
Sourcepub fn set_send_buffer_size(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
size: usize,
)
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.
Sourcepub fn send_buffer_size(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
) -> Option<usize>
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.
Sourcepub fn set_receive_buffer_size(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
size: usize,
)
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.
Sourcepub fn receive_buffer_size(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
) -> Option<usize>
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.
Sourcepub fn set_reuseaddr(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
reuse: bool,
) -> Result<(), SetReuseAddrError>
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.
Sourcepub fn reuseaddr(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
) -> bool
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.
Sourcepub fn dual_stack_enabled(
&mut self,
id: &TcpSocketId<I, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, C::BindingsContext>,
) -> Result<bool, NotDualStackCapableError>
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.
Sourcepub fn set_mark(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
domain: MarkDomain,
mark: Mark,
)
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.
Sourcepub fn get_mark(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
domain: MarkDomain,
) -> Mark
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.
Sourcepub fn set_dual_stack_enabled(
&mut self,
id: &TcpSocketId<I, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, C::BindingsContext>,
value: bool,
) -> Result<(), SetDualStackEnabledError>
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.
Sourcepub fn get_socket_error(
&mut self,
id: &TcpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>,
) -> Option<ConnectionError>
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.
Sourcepub 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>
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.
Sourcepub fn inspect<N>(&mut self, inspector: &mut N)where
N: Inspector + InspectorDeviceExt<<C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>,
pub fn inspect<N>(&mut self, inspector: &mut N)where
N: Inspector + InspectorDeviceExt<<C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>,
Provides access to shared and per-socket TCP stats via a visitor.
Sourcepub 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>
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
.
Sourcepub 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>
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
.