coap_add_resource, coap_can_exit, coap_context_get_csm_max_message_size, coap_context_get_csm_timeout,
coap_context_get_max_handshake_sessions, coap_context_get_max_idle_sessions, coap_context_get_session_timeout,
coap_context_set_block_mode, coap_context_set_csm_max_message_size, coap_context_set_csm_timeout,
coap_context_set_keepalive, coap_context_set_max_handshake_sessions, coap_context_set_max_idle_sessions,
coap_context_set_session_timeout, coap_context_t, coap_event_t, coap_event_t_COAP_EVENT_BAD_PACKET,
coap_event_t_COAP_EVENT_DTLS_CLOSED, coap_event_t_COAP_EVENT_DTLS_CONNECTED, coap_event_t_COAP_EVENT_DTLS_ERROR,
coap_event_t_COAP_EVENT_OSCORE_DECRYPTION_FAILURE, coap_event_t_COAP_EVENT_OSCORE_INTERNAL_ERROR,
coap_event_t_COAP_EVENT_SESSION_FAILED, coap_event_t_COAP_EVENT_TCP_CLOSED, coap_event_t_COAP_EVENT_TCP_CONNECTED,
coap_event_t_COAP_EVENT_TCP_FAILED, coap_event_t_COAP_EVENT_WS_CLOSED, coap_event_t_COAP_EVENT_WS_CONNECTED,
coap_event_t_COAP_EVENT_WS_PACKET_SIZE, coap_event_t_COAP_EVENT_XMIT_BLOCK_FAIL, coap_free_context,
coap_get_app_data, coap_io_process, coap_new_context, coap_proto_t, coap_proto_t_COAP_PROTO_DTLS,
coap_register_response_handler, coap_set_app_data, coap_startup_with_feature_checks, COAP_BLOCK_SINGLE_BODY,
use std::{any::Any, ffi::c_void, fmt::Debug, net::SocketAddr, ops::Sub, sync::Once, time::Duration};
error::{ContextConfigurationError, EndpointCreationError, IoProcessError, MulticastGroupJoinError},
/// Provided pointer must point to as valid instance of a raw context whose application data
coap_event_t_COAP_EVENT_SESSION_CONNECTED => handler.handle_session_connected(&mut session),
coap_event_t_COAP_EVENT_OSCORE_INTERNAL_ERROR => handler.handle_oscore_internal_error(&mut session),
coap_event_t_COAP_EVENT_OSCORE_DECODE_ERROR => handler.handle_oscore_decode_error(&mut session),
// For server-side sessions: Ensure that server-side session wrappers are either kept in memory or dropped when needed.
/// Returns [`ContextConfigurationError::Unknown`] if the call to the underlying libcoap library
/// function fails and [`ContextConfigurationError::CryptoContextAlreadySet`] if the PSK context
pub fn set_psk_context(&mut self, psk_context: ServerPskContext<'a>) -> Result<(), ContextConfigurationError> {
/// Returns [`ContextConfigurationError::Unknown`] if the call to the underlying libcoap library
/// function fails and [`ContextConfigurationError::CryptoContextAlreadySet`] if the PSK context
/// See the Rust standard library documentation on [FFI conversions](https://doc.rust-lang.org/std/ffi/index.html#conversions])
/// 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.
pub fn shutdown(mut self, exit_wait_timeout: Option<Duration>) -> Result<(), IoProcessError> {
fn add_endpoint(&mut self, addr: SocketAddr, proto: coap_proto_t) -> Result<(), EndpointCreationError> {
/// Note that in order to actually connect to DTLS clients, you need to set a crypto provider
/// If `ifname` is set to `None`, the first appropriate interface will be chosen by the operating system.
// SAFETY: `inner_ref.raw_context` is always valid by construction of this type, group and interface name are pointers to valid C strings.
/// Return the duration that idle server-side sessions are kept alive if they are not referenced
/// Set the duration that idle server-side sessions are kept alive if they are not referenced or
unsafe { coap_context_set_max_handshake_sessions(self.inner.borrow().raw_context, max_handshake_sessions) };
unsafe { coap_context_set_max_idle_sessions(self.inner.borrow().raw_context, max_idle_sessions) };
unsafe { coap_context_set_csm_max_message_size(self.inner.borrow().raw_context, csm_max_message_size) };
/// In general, you should not do anything that would interfere with the safe functions of this
/// - Associating raw resources with the context and not removing them before the context is
/// - Calling `coap_free_context()` on this context (for obvious reasons, this will probably
// the default (elided) lifetimes are correct (the pointer is valid as long as the endpoint
/// In general, you should not do anything that would interfere with the safe functions of this
/// - Calling `coap_free_context()` on this context (for obvious reasons, this will probably