Struct libcoap_rs::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
sourceimpl<'a> CoapContext<'a>
impl<'a> CoapContext<'a>
sourcepub fn new() -> Result<CoapContext<'a>, ContextCreationError>
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?).
sourceimpl CoapContext<'_>
impl CoapContext<'_>
sourcepub fn shutdown(
self,
exit_wait_timeout: Option<Duration>
) -> Result<(), IoProcessError>
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.
sourcepub fn add_endpoint_udp(
&mut self,
addr: SocketAddr
) -> Result<(), EndpointCreationError>
pub fn add_endpoint_udp(
&mut self,
addr: SocketAddr
) -> Result<(), EndpointCreationError>
Creates a new UDP endpoint that is bound to the given address.
sourcepub fn add_endpoint_tcp(
&mut self,
_addr: SocketAddr
) -> Result<(), EndpointCreationError>
pub fn add_endpoint_tcp(
&mut self,
_addr: SocketAddr
) -> Result<(), EndpointCreationError>
TODO
sourcepub fn add_endpoint_dtls(
&mut self,
addr: SocketAddr
) -> Result<(), EndpointCreationError>
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()
sourcepub fn add_endpoint_tls(
&mut self,
_addr: SocketAddr
) -> Result<(), EndpointCreationError>
pub fn add_endpoint_tls(
&mut self,
_addr: SocketAddr
) -> Result<(), EndpointCreationError>
TODO
sourcepub fn add_resource<D: Any + ?Sized + Debug>(&mut self, res: CoapResource<D>)
pub fn add_resource<D: Any + ?Sized + Debug>(&mut self, res: CoapResource<D>)
Adds the given resource to the resource pool of this context.
sourcepub fn set_server_crypto_provider(
&mut self,
provider: Option<Box<dyn CoapServerCryptoProvider>>
)
pub fn set_server_crypto_provider(
&mut self,
provider: Option<Box<dyn CoapServerCryptoProvider>>
)
Sets the server-side cryptography information provider.
sourcepub fn do_io(
&mut self,
timeout: Option<Duration>
) -> Result<Duration, IoProcessError>
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.
sourcepub fn session_timeout(&self) -> Duration
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.
sourcepub fn set_session_timeout(&self, timeout: Duration)
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).
sourcepub fn max_handshake_sessions(&self) -> c_uint
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.
sourcepub fn set_max_handshake_sessions(&self, max_handshake_sessions: c_uint)
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.
sourcepub fn max_idle_sessions(&self) -> c_uint
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.
sourcepub fn set_max_idle_sessions(&self, max_idle_sessions: c_uint)
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.
sourcepub fn csm_max_message_size(&self) -> u32
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.
sourcepub fn set_csm_max_message_size(&self, csm_max_message_size: u32)
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.
sourcepub fn csm_timeout(&self) -> Duration
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.
sourcepub fn set_csm_timeout(&self, csm_timeout: Duration)
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).
sourcepub fn set_keepalive(&self, timeout: Option<Duration>)
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).