Struct CoapContext

Source
pub struct CoapContext<'a> { /* private fields */ }
Expand description

A CoAP Context — container for general state and configuration information relating to CoAP

The equivalent to the coap_context_t type in libcoap.

Implementations§

Source§

impl<'a> CoapContext<'a>

Source

pub fn new() -> Result<CoapContext<'a>, ContextCreationError>

Creates a new context.

§Errors

Returns an error if the underlying libcoap library was unable to create a new context (probably an allocation error?).

Source§

impl CoapContext<'_>

Source

pub fn shutdown( self, exit_wait_timeout: Option<Duration>, ) -> Result<(), IoProcessError>

Performs a controlled shutdown of the CoAP context.

This will perform all still outstanding IO operations until coap_can_exit() confirms that the context has no more outstanding IO and can be dropped without interrupting sessions.

Source

pub fn add_endpoint_udp( &mut self, addr: SocketAddr, ) -> Result<(), EndpointCreationError>

Creates a new UDP endpoint that is bound to the given address.

Source

pub fn add_endpoint_tcp( &mut self, _addr: SocketAddr, ) -> Result<(), EndpointCreationError>

TODO

Source

pub fn add_endpoint_dtls( &mut self, addr: SocketAddr, ) -> Result<(), EndpointCreationError>

Creates a new DTLS endpoint that is bound to the given address.

Note that in order to actually connect to DTLS clients, you need to set a crypto provider using set_server_crypto_provider()

Source

pub fn add_endpoint_tls( &mut self, _addr: SocketAddr, ) -> Result<(), EndpointCreationError>

TODO

Source

pub fn add_resource<D: Any + ?Sized + Debug>(&mut self, res: CoapResource<D>)

Adds the given resource to the resource pool of this context.

Source

pub fn set_server_crypto_provider( &mut self, provider: Option<Box<dyn CoapServerCryptoProvider>>, )

Sets the server-side cryptography information provider.

Source

pub fn do_io( &mut self, timeout: Option<Duration>, ) -> Result<Duration, IoProcessError>

Performs currently outstanding IO operations, waiting for a maximum duration of timeout.

This is the function where most of the IO operations made using this library are actually executed. It is recommended to call this function in a loop for as long as the CoAP context is used.

Source

pub fn session_timeout(&self) -> Duration

Return the duration that idle server-side sessions are kept alive if they are not referenced or used anywhere else.

Source

pub fn set_session_timeout(&self, timeout: Duration)

Set the duration that idle server-side sessions are kept alive if they are not referenced or used anywhere else.

§Panics

Panics if the provided duration is too large to be provided to libcoap (larger than a libc::c_uint).

Source

pub fn max_handshake_sessions(&self) -> c_uint

Returns the maximum number of server-side sessions that can concurrently be in a handshake state.

If this number is exceeded, no new handshakes will be accepted.

Source

pub fn set_max_handshake_sessions(&self, max_handshake_sessions: c_uint)

Sets the maximum number of server-side sessions that can concurrently be in a handshake state.

If this number is exceeded, no new handshakes will be accepted.

Source

pub fn max_idle_sessions(&self) -> c_uint

Returns the maximum number of idle server-side sessions for this context.

If this number is exceeded, the oldest unreferenced session will be freed.

Source

pub fn set_max_idle_sessions(&self, max_idle_sessions: c_uint)

Sets the maximum number of idle server-side sessions for this context.

If this number is exceeded, the oldest unreferenced session will be freed.

Source

pub fn csm_max_message_size(&self) -> u32

Returns the maximum size for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn set_csm_max_message_size(&self, csm_max_message_size: u32)

Sets the maximum size for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn csm_timeout(&self) -> Duration

Returns the timeout for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

Source

pub fn set_csm_timeout(&self, csm_timeout: Duration)

Sets the timeout for Capabilities and Settings Messages

CSMs are used in CoAP over TCP as specified in RFC 8323, Section 5.3.

§Panics

Panics if the provided timeout is too large for libcoap (> u32::MAX).

Source

pub fn set_keepalive(&self, timeout: Option<Duration>)

Sets the number of seconds to wait before sending a CoAP keepalive message for idle sessions.

If the provided value is None, CoAP-level keepalive messages will be disabled.

§Panics

Panics if the provided duration is too large to be provided to libcoap (larger than a libc::c_uint).

Trait Implementations§

Source§

impl<'a> Debug for CoapContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CoapContext<'a>

§

impl<'a> !RefUnwindSafe for CoapContext<'a>

§

impl<'a> !Send for CoapContext<'a>

§

impl<'a> !Sync for CoapContext<'a>

§

impl<'a> Unpin for CoapContext<'a>

§

impl<'a> !UnwindSafe for CoapContext<'a>

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,