Struct netstack3_datagram::DatagramApi

source ·
pub struct DatagramApi<I, C, S>(/* private fields */);
Expand description

The shared datagram socket API.

Implementations§

source§

impl<I, C, S> DatagramApi<I, C, S>

source

pub fn new(ctx: C) -> Self

Creates a new DatagramApi from ctx.

source

pub fn wrap(ctx: &mut C) -> &mut Self

Creates a mutable borrow of a DatagramApi from a mutable borrow of C.

source§

impl<I, C, S> DatagramApi<I, C, S>
where I: IpExt, C: ContextPair, C::BindingsContext: DatagramStateBindingsContext<I, S>, C::CoreContext: DatagramStateContext<I, C::BindingsContext, S>, S: DatagramSocketSpec,

source

pub fn create( &mut self, external_data: S::ExternalData<I>, ) -> S::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Creates a new datagram socket and inserts it into the list of all open datagram sockets for the provided spec S.

The caller is responsible for calling [close] when it’s done with the resource.

source

pub fn collect_all_sockets( &mut self, ) -> Vec<S::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>>

Collects all currently opened sockets.

source

pub fn close( &mut self, id: <S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> RemoveResourceResultWithContext<S::ExternalData<I>, C::BindingsContext>

Closes the socket.

source

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

Returns the socket’s bound/connection state information.

source

pub fn listen( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, addr: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, local_id: Option<<S::AddrSpec as SocketMapAddrSpec>::LocalIdentifier>, ) -> Result<(), Either<ExpectedUnboundError, LocalAddressError>>

Binds the socket to a local address and port.

source

pub fn connect( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, remote_ip: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, remote_id: <S::AddrSpec as SocketMapAddrSpec>::RemoteIdentifier, extra: S::ConnStateExtra, ) -> Result<(), ConnectError>

Connects the datagram socket.

source

pub fn disconnect_connected( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> Result<(), ExpectedConnError>

Disconnects a connected socket.

source

pub fn get_shutdown_connected( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> Option<ShutdownType>

Returns the socket’s shutdown state.

source

pub fn shutdown_connected( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, which: ShutdownType, ) -> Result<(), ExpectedConnError>

Shuts down the socket.

which determines the shutdown type.

source

pub fn send_conn<B: BufferMut>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, body: B, ) -> Result<(), SendError<S::SerializeError>>

Sends data over a connected datagram socket.

source

pub fn send_to<B: BufferMut>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, remote_ip: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, remote_identifier: <S::AddrSpec as SocketMapAddrSpec>::RemoteIdentifier, body: B, ) -> Result<(), Either<LocalAddressError, SendToError<S::SerializeError>>>

Sends a datagram to the provided remote node.

source

pub fn get_bound_device( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> Option<<<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Returns the bound device for the socket.

source

pub fn set_device( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, new_device: Option<&<<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, ) -> Result<(), SocketError>

Sets the socket’s bound device to new_device.

source

pub fn set_multicast_membership( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, multicast_group: MulticastAddr<I::Addr>, interface: MulticastMembershipInterfaceSelector<I::Addr, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, want_membership: bool, ) -> Result<(), SetMulticastMembershipError>

Sets the specified socket’s membership status for the given group.

An error is returned if the membership change request is invalid (e.g. leaving a group that was not joined, or joining a group multiple times) or if the device to use to join is unspecified or conflicts with the existing socket state.

source

pub fn update_ip_hop_limit( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, update: impl FnOnce(&mut SocketHopLimits<I>), )

Updates the socket’s IP hop limits.

source

pub fn get_ip_hop_limits( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> HopLimits

Returns the socket’s IP hop limits.

source

pub fn with_other_stack_ip_options_mut_if_unbound<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&mut S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>) -> R, ) -> Result<R, ExpectedUnboundError>

Calls the callback with mutable access to [S::OtherStackIpOptions<I, D>].

If the socket is bound, the callback is not called, and instead an ExpectedUnboundError is returned.

source

pub fn with_other_stack_ip_options_mut<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&mut S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>) -> R, ) -> R

Calls the callback with mutable access to [S::OtherStackIpOptions<I, D>].

source

pub fn with_other_stack_ip_options<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>) -> R, ) -> R

Calls the callback with access to [S::OtherStackIpOptions<I, D>].

source

pub fn with_other_stack_ip_options_and_default_hop_limits<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, HopLimits) -> R, ) -> Result<R, NotDualStackCapableError>

Calls the callback with access to [S::OtherStackIpOptions<I, D>], and the default [HopLimits] for I::OtherVersion.

If dualstack operations are not supported, the callback is not called, and instead NotDualStackCapableError is returned.

source

pub fn with_both_stacks_ip_options_mut<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&mut DatagramIpSpecificSocketOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, &mut S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>) -> R, ) -> R

Calls the callback with mutable access to DatagramIpSpecificSocketOptions<I,D> and [S::OtherStackIpOptions<I, D>].

source

pub fn with_both_stacks_ip_options<R>( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, cb: impl FnOnce(&DatagramIpSpecificSocketOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, &S::OtherStackIpOptions<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>) -> R, ) -> R

Calls the callback with access to DatagramIpSpecificSocketOptions<I, D> and [S::OtherStackIpOptions<I, D>].

source

pub fn update_sharing( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, f: impl FnOnce(&mut S::SharingState), ) -> Result<(), ExpectedUnboundError>

Updates the socket’s sharing state to the result of f.

f is given mutable access to the sharing state and is called under the socket lock, allowing for atomic updates to the sharing state.

source

pub fn get_sharing( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> S::SharingState

Returns the socket’s sharing state.

source

pub fn set_ip_transparent( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, value: bool, )

Sets the IP transparent option.

source

pub fn get_ip_transparent( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> bool

Returns the IP transparent option.

source

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

Sets the socket mark at domain.

source

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

Returns the socket mark at domain.

source

pub fn set_broadcast( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, value: Option<I::BroadcastMarker>, )

Sets the broadcast option.

source

pub fn get_broadcast( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> Option<I::BroadcastMarker>

Returns the broadcast option.

source

pub fn set_multicast_interface( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, value: Option<&<<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, )

Sets the multicast interface for outgoing multicast packets.

source

pub fn get_multicast_interface( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> Option<<<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Returns the configured multicast interface.

source

pub fn set_multicast_loop( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, value: bool, )

Sets the multicast loopback flag.

source

pub fn get_multicast_loop( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> bool

Returns the multicast loopback flag.

source

pub fn set_dscp_and_ecn( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, value: DscpAndEcn, )

Sets the Traffic Class option.

source

pub fn get_dscp_and_ecn( &mut self, id: &<S as DatagramSocketSpec>::SocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, ) -> DscpAndEcn

Returns the Traffic Class option.

Trait Implementations§

source§

impl<I, C, S> RefCast for DatagramApi<I, C, S>

§

type From = C

source§

fn ref_cast(_from: &Self::From) -> &Self

source§

fn ref_cast_mut(_from: &mut Self::From) -> &mut Self

Auto Trait Implementations§

§

impl<I, C, S> Freeze for DatagramApi<I, C, S>
where C: Freeze,

§

impl<I, C, S> RefUnwindSafe for DatagramApi<I, C, S>

§

impl<I, C, S> Send for DatagramApi<I, C, S>
where C: Send, S: Send, I: Send,

§

impl<I, C, S> Sync for DatagramApi<I, C, S>
where C: Sync, S: Sync, I: Sync,

§

impl<I, C, S> Unpin for DatagramApi<I, C, S>
where C: Unpin, S: Unpin, I: Unpin,

§

impl<I, C, S> UnwindSafe for DatagramApi<I, C, S>
where C: UnwindSafe, S: 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.
§

impl<L, T> UnlockedAccess<L> for T
where L: UnlockedAccessMarkerFor<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.
§

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

§

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