Client: Remove (D)TLS / WebSocket startup call-back timing window

Add in new functions
  coap_new_client_session3()
  coap_new_client_session_pki3()
  coap_new_client_session_psk3()
  coap_new_client_session_oscore3()
  coap_new_client_session_oscore_pki3()
  coap_new_client_session_oscore_psk3()
which effectively does coap_session_set_app_data2() and
coap_ws_set_host_request() early on in the session set up cycle.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2026-01-08 17:51:10 +00:00
1 parent c9135b6b26
commit d80fa1497d
25 files changed
+918 -212

No files matched your search

+9 -3
View File
@@ -32,7 +32,6 @@ TXT3 = coap_address.txt \
coap_handler.txt \
coap_init.txt \
coap_io.txt \
coap_io_loop.txt \
coap_keepalive.txt \
coap_locking.txt \
coap_logging.txt \
@@ -49,6 +48,7 @@ TXT3 = coap_address.txt \
coap_session.txt \
coap_string.txt \
coap_supported.txt \
coap_threads.txt \
coap_tls_library.txt \
coap_uri.txt \
coap_websockets.txt
@@ -132,8 +132,12 @@ install-man: install-man3 install-man5 install-man7
@echo ".so man3/coap_context.3" > coap_context_set_session_reconnect_time.3
@echo ".so man3/coap_context.3" > coap_context_set_session_reconnect_time2.3
@echo ".so man3/coap_context.3" > coap_register_option.3
@echo ".so man3/coap_deprecated.3" > coap_set_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_get_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_new_client_session_oscore_psk.3
@echo ".so man3/coap_deprecated.3" > coap_new_client_session_psk.3
@echo ".so man3/coap_deprecated.3" > coap_new_client_session_psk2.3
@echo ".so man3/coap_deprecated.3" > coap_new_client_session_pki.3
@echo ".so man3/coap_deprecated.3" > coap_option_clrb.3
@echo ".so man3/coap_deprecated.3" > coap_option_getb.3
@echo ".so man3/coap_deprecated.3" > coap_option_setb.3
@echo ".so man3/coap_deprecated.3" > coap_read.3
@echo ".so man3/coap_deprecated.3" > coap_register_handler.3
@@ -141,6 +145,8 @@ install-man: install-man3 install-man5 install-man7
@echo ".so man3/coap_deprecated.3" > coap_run_once.3
@echo ".so man3/coap_deprecated.3" > coap_set_event_handler.3
@echo ".so man3/coap_deprecated.3" > coap_write.3
@echo ".so man3/coap_deprecated.3" > coap_get_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_set_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_async_set_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_cache_set_app_data.3
@echo ".so man3/coap_deprecated.3" > coap_context_set_app_data.3
+75 -4
View File
@@ -16,7 +16,13 @@ coap_context_get_csm_timeout,
coap_context_set_csm_timeout,
coap_context_set_psk,
coap_encode_var_bytes,
coap_new_client_session,
coap_new_client_session_oscore,
coap_new_client_session_oscore_pki,
coap_new_client_session_oscore_psk,
coap_new_client_session_pki,
coap_new_client_session_psk,
coap_new_client_session_psk2,
coap_option_clrb,
coap_option_getb,
coap_option_setb,
@@ -50,11 +56,37 @@ const uint8_t *_key_, size_t _key_len_);*
*int coap_encode_var_bytes(uint8_t *_buffer_, unsigned int _value_);*
*coap_session_t *coap_new_client_session(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_);*
*coap_session_t *coap_new_client_session_oscore(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_oscore_conf_t *_oscore_conf_);*
*coap_session_t *coap_new_client_session_oscore_psk(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_dtls_cpsk_t *_psk_data_,
coap_oscore_conf_t *_oscore_conf_);*
*coap_session_t *coap_new_client_session_oscore_pki(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_dtls_pki_t *_pki_data_,
coap_oscore_conf_t *_oscore_conf_);*
*coap_session_t *coap_new_client_session_pki(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_, coap_proto_t
_proto_, coap_dtls_pki_t *_setup_data_);*
*coap_session_t *coap_new_client_session_psk(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, const char *_identity_, const uint8_t *_key_,
unsigned _key_len_);*
*coap_session_t *coap_new_client_session_psk2(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_, coap_proto_t
_proto_, coap_dtls_cpsk_t *_setup_data_);*
*int coap_option_clrb(coap_opt_filter_t *_filter_, uint16_t _type_);*
*int coap_option_getb(coap_opt_filter_t *_filter_, uint16_t _type_);*
@@ -135,11 +167,48 @@ by the use of the coap_dtls_spsk_t structure.
The *coap_encode_var_bytes*() function is replaced by
*coap_encode_var_safe*(3).
*Function: coap_new_client_session()*
The *coap_new_client_session*() function is replaced by
*coap_new_client_session3*(3) which supports additional session app_data to
remove startup call-back timing issues.
*Function: coap_new_client_session_oscore()*
The *coap_new_client_session_oscore*() function is replaced by
*coap_new_client_session_oscore3*(3) which supports additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_new_client_session_oscore_pki()*
The *coap_new_client_session_oscore_pki*() function is replaced by
*coap_new_client_session_oscore_pki3*(3) which supports additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_new_client_session_oscore_psk()*
The *coap_new_client_session_oscore_psk*() function is replaced by
*coap_new_client_session_oscore_psk3*(3) which supports additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_new_client_session_pki()*
The *coap_new_client_session_pki*() function is replaced by
*coap_new_client_session_pki3*(3) which supports additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_new_client_session_psk()*
The *coap_new_client_session_psk*() function is replaced by
*coap_new_client_session_psk2*(3) which gives additional PSK configuration capability
by the use of the coap_dtls_cpsk_t structure.
*coap_new_client_session_psk3*(3) which gives additional PSK configuration capability
by the use of the coap_dtls_cpsk_t structure along with additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_new_client_session_psk2()*
The *coap_new_client_session_psk2*() function is replaced by
*coap_new_client_session_psk3*(3) which supports additional session app_data and
ws_host to remove startup call-back timing issues.
*Function: coap_option_clrb()*
@@ -218,8 +287,10 @@ negotiation response from the peer.
*coap_encode_var_bytes*() returns either the length of bytes encoded (which can
be 0 when encoding 0) or 0 on failure.
*coap_new_client_session_psk*() returns a new session if success, NULL on
failure.
*coap_new_client_session*(), *coap_new_client_session_oscore*(),
*coap_new_client_session_oscore_psk*(), *coap_new_client_session_oscore_pki*(),
*coap_new_client_session_psk*(), *coap_new_client_session_psk2*() and
*coap_new_client_session_pki*() return a new session if success, NULL on failure.
*coap_option_clrb*() returns 1 if bit was set, -1 otherwise.
+64 -26
View File
@@ -11,9 +11,9 @@ coap_endpoint_client(3)
NAME
----
coap_endpoint_client,
coap_new_client_session,
coap_new_client_session_psk2,
coap_new_client_session_pki,
coap_new_client_session3,
coap_new_client_session_psk3,
coap_new_client_session_pki3,
coap_session_set_mtu,
coap_session_max_pdu_size,
coap_mcast_set_hops
@@ -23,17 +23,20 @@ SYNOPSIS
--------
*#include <coap@LIBCOAP_API_VERSION@/coap.h>*
*coap_session_t *coap_new_client_session(coap_context_t *_context_,
*coap_session_t *coap_new_client_session3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_);*
coap_proto_t _proto_, void *_app_data_, coap_app_data_free_callback_t _callback_,
coap_str_const_t *_ws_host_);*
*coap_session_t *coap_new_client_session_psk2(coap_context_t *_context_,
*coap_session_t *coap_new_client_session_psk3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_, coap_proto_t
_proto_, coap_dtls_cpsk_t *_setup_data_);*
_proto_, coap_dtls_cpsk_t *_setup_data_, void *_app_data_,
coap_app_data_free_callback_t _callback_, coap_str_const_t *_ws_host_);*
*coap_session_t *coap_new_client_session_pki(coap_context_t *_context_,
*coap_session_t *coap_new_client_session_pki3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_, coap_proto_t
_proto_, coap_dtls_pki_t *_setup_data_);*
_proto_, coap_dtls_pki_t *_setup_data_, void *_app_data_,
coap_app_data_free_callback_t _callback_, coap_str_const_t *_ws_host_);*
*void coap_session_set_mtu(coap_session_t *_session_, unsigned _mtu_);*
@@ -88,7 +91,7 @@ In principle the set-up sequence for CoAP client endpoints looks like
----
coap_new_context()
coap_context_set_pki_root_cas() - if the root CAs need to be updated and using PKI
coap_new_client_session(), coap_new_client_session_pki() or coap_new_client_session_psk2()
coap_new_client_session3(), coap_new_client_session_pki3() or coap_new_client_session_psk3()
----
Multiple client endpoints and hence sessions are supported per _context_.
@@ -136,9 +139,9 @@ unix domain path to connect to must be specified.
FUNCTIONS
---------
*Function: coap_new_client_session()*
*Function: coap_new_client_session3()*
The *coap_new_client_session*() function creates a client endpoint for a
The *coap_new_client_session3*() function creates a client endpoint for a
specific _context_ and initiates a new client session to the specified
_server_ using the CoAP protocol _proto_ as defined above. If the port is set
to 0 in _server_ (for AF_INET or AF_INET6), then the default CoAP port is used.
@@ -150,13 +153,23 @@ appropriate *coap_address_t*. If _local_if_ is defined, the address families
for _local_if_ and _server_ must be identical. The session will initially have
a reference count of 1.
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
To stop using a client session, the reference count must be decremented to 0
by calling *coap_session_release*(3). See *coap_session*(3). This will remove
the client endpoint's _session_ and all its associated information.
*Function: coap_new_client_session_pki()*
*Function: coap_new_client_session_pki3()*
The *coap_new_client_session_pki*() function, for a specific _context_, is
The *coap_new_client_session_pki3*() function, for a specific _context_, is
used to configure the (D)TLS context using the _setup_data_ variables as defined
in the coap_dtls_pki_t structure in the newly created endpoint session -
see *coap_encryption*(3). The connection is to the specified _server_ using
@@ -170,13 +183,23 @@ appropriate *coap_address_t*. If _local_if_ is defined, the address families
for _local_if_ and _server_ must be identical. The session will initially have
a reference count of 1.
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
To stop using a client session, the reference count must be decremented to 0
by calling *coap_session_release*(3). See *coap_session*(3). This will remove
the client endpoint's _session_ and all its associated information.
*Function: coap_new_client_session_psk2()*
*Function: coap_new_client_session_psk3()*
The *coap_new_client_session_psk2*() function, for a specific _context_, is
The *coap_new_client_session_psk3*() function, for a specific _context_, is
used to configure the (D)TLS context using the _setup_data_ variables as defined
in the coap_dtls_cpsk_t structure in the newly created endpoint session -
see *coap_encryption*(3). The connection is to the specified _server_ using
@@ -190,6 +213,16 @@ appropriate *coap_address_t*. If _local_if_ is defined, the address families
for _local_if_ and _server_ must be identical. The session will initially have
a reference count of 1.
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
To stop using a client session, the reference count must be decremented to 0
by calling *coap_session_release*(3). See *coap_session*(3). This will remove
the client endpoint's _session_ and all its associated information.
@@ -216,8 +249,8 @@ _session_.
RETURN VALUES
-------------
*coap_new_client_session*(), *coap_new_client_session_psk2*(),
*coap_new_client_session_pki*() return a newly created client
*coap_new_client_session3*(), *coap_new_client_session_psk3*(),
*coap_new_client_session_pki3*() return a newly created client
session or NULL if there is a creation failure.
*coap_session_max_pdu_size*() returns the MTU size.
@@ -253,7 +286,8 @@ setup_client_session(struct in_addr ip_address) {
server.addr.sin.sin_addr = ip_address;
server.addr.sin.sin_port = htons(5683);
session = coap_new_client_session(context, NULL, &server, COAP_PROTO_UDP);
session = coap_new_client_session3(context, NULL, &server, COAP_PROTO_UDP,
NULL, NULL, NULL);
if (!session) {
coap_free_context(context);
return NULL;
@@ -301,7 +335,8 @@ setup_client_session(const char *server_ud) {
/* Only do this if you know it is safe to do so */
unlink(local.addr.cun.sun_path);
session = coap_new_client_session(context, &local, &server, COAP_PROTO_UDP);
session = coap_new_client_session3(context, &local, &server, COAP_PROTO_UDP,
NULL, NULL, NULL);
if (!session) {
coap_free_context(context);
return NULL;
@@ -399,8 +434,9 @@ setup_client_session_pki(const char *host,
dtls_pki.pki_key.key.pem.public_cert = public_cert_file;
dtls_pki.pki_key.key.pem.private_key = private_key_file;
session = coap_new_client_session_pki(context, NULL, &server,
COAP_PROTO_DTLS, &dtls_pki);
session = coap_new_client_session_pki3(context, NULL, &server,
COAP_PROTO_DTLS, &dtls_pki,
NULL, NULL, NULL);
if (!session) {
coap_free_context(context);
return NULL;
@@ -475,8 +511,9 @@ setup_client_session_psk(const char *host,
dtls_psk.psk_info.identity.length = identity_len;
dtls_psk.psk_info.key.s = key;
dtls_psk.psk_info.key.length = key_len;
session = coap_new_client_session_psk2(context, NULL, &server,
COAP_PROTO_DTLS, &dtls_psk);
session = coap_new_client_session_psk3(context, NULL, &server,
COAP_PROTO_DTLS, &dtls_psk,
NULL, NULL, NULL);
if (!session) {
coap_free_context(context);
return NULL;
@@ -513,8 +550,9 @@ setup_client_session_dtls(struct in_addr ip_address) {
server.addr.sin.sin_addr = ip_address;
server.addr.sin.sin_port = htons(5683);
session = coap_new_client_session(context, NULL, &server,
COAP_PROTO_DTLS);
session = coap_new_client_session3(context, NULL, &server,
COAP_PROTO_DTLS,
NULL, NULL, NULL);
if (!session) {
coap_free_context(context);
return NULL;
+3 -1
View File
@@ -137,8 +137,10 @@ _timeout_ms_ set to COAP_IO_NO_WAIT. +
will then be using *epoll* internally to process all the file descriptors of
the different sessions.
:NOTE:* With multi-threading protection enabled, it is possible to
*NOTE:* With multi-threading protection enabled, it is possible to
call *coap_io_process*() from multiple threads to do some load balancing.
However, *coap_io_process*() must not be called from within a call-back
handler (as that may recursively call the same call-back handler).
See EXAMPLES below.
+53 -20
View File
@@ -15,9 +15,9 @@ coap_new_oscore_conf,
coap_delete_oscore_conf,
coap_new_oscore_recipient,
coap_delete_oscore_recipient,
coap_new_client_session_oscore,
coap_new_client_session_oscore_pki,
coap_new_client_session_oscore_psk,
coap_new_client_session_oscore3,
coap_new_client_session_oscore_pki3,
coap_new_client_session_oscore_psk3,
coap_context_oscore_server
- Work with CoAP OSCORE
@@ -37,19 +37,22 @@ coap_bin_const_t *_recipient_id_);*
*int coap_delete_oscore_recipient(coap_context_t *_context_,
coap_bin_const_t *_recipient_id_);*
*coap_session_t *coap_new_client_session_oscore(coap_context_t *_context_,
*coap_session_t *coap_new_client_session_oscore3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_oscore_conf_t *_oscore_conf_);*
coap_proto_t _proto_, coap_oscore_conf_t *_oscore_conf_, void *_app_data_,
coap_app_data_free_callback_t _callback_, coap_str_const_t *_ws_host_);*
*coap_session_t *coap_new_client_session_oscore_psk(coap_context_t *_context_,
*coap_session_t *coap_new_client_session_oscore_psk3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_dtls_cpsk_t *_psk_data_,
coap_oscore_conf_t *_oscore_conf_);*
coap_oscore_conf_t *_oscore_conf_, void *_app_data_,
coap_app_data_free_callback_t _callback_, coap_str_const_t *_ws_host_);*
*coap_session_t *coap_new_client_session_oscore_pki(coap_context_t *_context_,
*coap_session_t *coap_new_client_session_oscore_pki3(coap_context_t *_context_,
const coap_address_t *_local_if_, const coap_address_t *_server_,
coap_proto_t _proto_, coap_dtls_pki_t *_pki_data_,
coap_oscore_conf_t *_oscore_conf_);*
coap_oscore_conf_t *_oscore_conf_, void *_app_data_,
coap_app_data_free_callback_t _callback_, coap_str_const_t *_ws_host_);*
*int coap_context_oscore_server(coap_context_t *_context_,
coap_oscore_conf_t *_oscore_conf_);*
@@ -144,10 +147,10 @@ coap_oscore_conf_t structure _oscore_conf_ as returned by
*coap_new_oscore_conf*(). Normally this function never needs to be called
as _oscore_conf_ is freed off by the call the client or server setup functions.
*Function: coap_new_client_session_oscore()*
*Function: coap_new_client_session_oscore3()*
The *coap_new_client_session_oscore*() is basically the same as
*coap_new_client_session*(3), but has an additional parameter _oscore_conf_
The *coap_new_client_session_oscore3*() is basically the same as
*coap_new_client_session3*(3), but has an additional parameter _oscore_conf_
that is created by *coap_new_oscore_conf*(). This function creates a
client endpoint for a specific _context_ and initiates a new client session
to the specified _server_ using the CoAP protocol _proto_ and OSCORE
@@ -157,10 +160,20 @@ Normally _local_if_ would be set to NULL, but by specifying _local_if_ the
source of the network session can be bound to a specific IP address or port.
The session will initially have a reference count of 1.
*Function: coap_new_client_session_oscore_psk()*
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
The *coap_new_client_session_oscore_psk*() is basically the same as
*coap_new_client_session_psk2*(3), but has an additional parameter
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
*Function: coap_new_client_session_oscore_psk3()*
The *coap_new_client_session_oscore_psk3*() is basically the same as
*coap_new_client_session_psk3*(3), but has an additional parameter
_oscore_conf_ that is created by *coap_new_oscore_conf*(). This
function, for a specific _context_, is used to configure the TLS context
using the _setup_data_ variables as defined in the coap_dtls_cpsk_t structure
@@ -172,10 +185,20 @@ port is used. Normally _local_if_ would be set to NULL, but by specifying
_local_if_ the source of the network session can be bound to a specific IP
address or port. The session will initially have a reference count of 1.
*Function: coap_new_client_session_oscore_pki()*
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
The *coap_new_client_session_oscore_pki*() is basically the same as
*coap_new_client_session_pki*(3), but has an additional parameter
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
*Function: coap_new_client_session_oscore_pki3()*
The *coap_new_client_session_oscore_pki3*() is basically the same as
*coap_new_client_session_pki3*(3), but has an additional parameter
_oscore_conf_ that is created by *coap_new_oscore_conf*(). This
function, for a specific _context_, is used to configure the TLS context using
the _setup_data_ variables as defined in the coap_dtls_pki_t structure in the
@@ -187,6 +210,16 @@ Normally _local_if_ would be set to NULL, but by specifying _local_if_ the
source of the network session can be bound to a specific IP address or port.
The session will initially have a reference count of 1.
_app_data_ and _callback_ are added to the returned session early on in the
session create cycle to remove any potential timing issues on a multi-threaded
system. If not required, then these can be set to NULL. See
*coap_session_set_app_data2*() for further information.
For _proto_ COAP_PROTO_WS or COAP_PROTO_WSS, _ws_host_ is added to the returned
session early on in the session create cycle to remove any potential timing
issues on a multi-threaded system. If not required, then this can be set to NULL.
See *coap_ws_set_host_request*(3) for further information.
*Function: coap_context_oscore_server()*
The *coap_context_oscore_server*() function is used to enable the server to
@@ -195,8 +228,8 @@ configure _oscore_conf_ (which is freed off by this call).
RETURN VALUES
-------------
*coap_new_client_session_oscore*(), *coap_new_client_session_oscore_psk*()
and *coap_new_client_session_oscore_pki*() return a newly created
*coap_new_client_session_oscore3*(), *coap_new_client_session_oscore_psk3*()
and *coap_new_client_session_oscore_pki3*() return a newly created
client session or NULL if there is a malloc or parameter failure.
*coap_new_oscore_conf*() returns a _coap_oscore_conf_t_
@@ -1,21 +1,21 @@
// -*- mode:doc; -*-
// vim: set syntax=asciidoc tw=0
coap_io_loop(3)
coap_threads(3)
===============
:doctype: manpage
:man source: coap_io_loop
:man source: coap_threads
:man version: @PACKAGE_VERSION@
:man manual: libcoap Manual
NAME
----
coap_io_loop,
coap_threads,
coap_io_process_loop,
coap_io_process_terminate_loop,
coap_io_process_configure_threads,
coap_io_process_remove_threads
- Work with CoAP threads doing coap_io_process
- Work with CoAP threads
SYNOPSIS
--------
@@ -42,14 +42,59 @@ or *-lcoap-@LIBCOAP_API_VERSION@-tinydtls*. Otherwise, link with
DESCRIPTION
-----------
This man page focuses on setting up and supporting multiple threads, each one
invoking *coap_io_process*(3) in a loop.
invoking *coap_io_process*(3) in a loop. There is no reason why an
application cannot set up and manage its own threading model.
Each thread can receive a packet (a different packet for each thread), call the
appropriate application call-back handler and potentially be spending time of
consequence in that handler without blocking the reciept of other input traffic.
Each thread calling *coap_io_process*(3) can receive a packet (a different packet
for each thread), call the appropriate application call-back handler and
potentially be spending time of consequence in that handler without blocking the
reciept of other input traffic.
These functions should be called from the main thread. It is assumed that
thread-safe code has been enabled.
These above listed functions should be called from the main thread. It is
assumed that thread-safe code has been enabled.
*CAUTION:* The thread interaction lock protection is done within the libcoap
library. There are several things that can cause thread interaction issues.
Any application thread that is not executing in the libcoap library or in
a libcoap call-back function must not modify any libcoap structure other
than by calling a libcoap Public API as there is no locking protection.
There are two types of libcoap call-back.
The first type of call-back is executing under the libcoap library lock protections
and so changes can safely be made to any structure that libcoap is using including
invoking any libcoap Public API calls.
The second type of call-back is executing without the libcoap lock protections and
so no mofications must take place other than by using the libcoap Public API. The
second type is used when there is a likelyhood that the call-back may block on an
external event and libcoap in general should not be blocked.
The list of the second type of call-backs are set up by the following functions:
[source, c]
----
coap_io_process_loop()
coap_register_request_handler()
coap_register_dynamic_resource_handler()
coap_register_response_handler()
coap_register_proxy_response_handler()
coap_lwip_set_input_wait_handler()
----
*coap_io_process*(3) must not be called from within a call-back handler as
*coap_io_process*(3) may then recursively call the same call-back handler.
Calling a Public API that initiates a process that will invoke a call-back
(potentially on a different thread) that requires external information to
be already set up may fail if this information is provided in a subsequent
Public API call (which may be done too late) sequentially done by the caller
of the initial Public API. An example of this is calling
*coap_new_client_session_psk2*(3) followed by *coap_session_set_app_data2*(3)
and the (D)TLS Identity call-cack is called before
*coap_session_set_app_data2*(3) completes. Use *coap_new_client_session_psk3*(3)
instead.
FUNCTIONS
---------
@@ -63,8 +108,8 @@ The thread calling *coap_io_process_loop*() will also be in a separate loop
that is calling *coap_io_process*(3), optionally calling _main_loop_code_
(if not NULL) with argument _main_loop_code_arg_. For the thread calling
*coap_io_process_loop*(), it will call _main_loop_code_ at least every
_timeout_ms_ milli-secs, the call to _main_loop_code_ start time aligned to
the nearest second.
_timeout_ms_ milli-secs, with the call to _main_loop_code_ start time is rounded
down to the nearest second if _timeout_ms_ is >= 1000.
_context_ defines the context to associate the threads with. _thread_count_
is the number of threads to be running *coap_io_process*(3) which includes the