Merge pull request #15288 from chrysn-pull-requests/gcoap_register_listener-document-single

net/goap: State and check that listeners are added individually
This commit is contained in:
benpicco 2020-10-26 00:07:58 +01:00 committed by GitHub
commit ddc4dad456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -690,6 +690,16 @@ kernel_pid_t gcoap_init(void);
/**
* @brief Starts listening for resource paths
*
* @pre @p listener is a valid pointer to a single listener (that is,
* `listener->next == NULL`)
*
* @note If you are tempted to register a pre-linked chain of listeners,
* consider placing all their resources in the resources array of a
* single listener instead. In the few cases where this does not work
* (that is, when the resources need a different `link_encoder` or other
* fields of the listener struct), they can just be registered
* individually.
*
* @param[in] listener Listener containing the resources.
*/
void gcoap_register_listener(gcoap_listener_t *listener);

View File

@ -702,6 +702,10 @@ kernel_pid_t gcoap_init(void)
void gcoap_register_listener(gcoap_listener_t *listener)
{
/* That item will be overridden, ensure that the user expecting different
* behavior will notice this. */
assert(listener->next == NULL);
if (!listener->link_encoder) {
listener->link_encoder = gcoap_encode_link;
}