Merge pull request #15147 from chrysn-pull-requests/gcoap-wkc-smallstuff

net/gcoap: Insert registrations at the front
This commit is contained in:
benpicco 2020-10-04 16:22:30 +02:00 committed by GitHub
commit be93529c89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 14 deletions

View File

@ -636,17 +636,12 @@ kernel_pid_t gcoap_init(void)
void gcoap_register_listener(gcoap_listener_t *listener)
{
/* Add the listener to the end of the linked list. */
gcoap_listener_t *_last = _coap_state.listeners;
while (_last->next) {
_last = _last->next;
}
listener->next = NULL;
if (!listener->link_encoder) {
listener->link_encoder = gcoap_encode_link;
}
_last->next = listener;
listener->next = _coap_state.listeners;
_coap_state.listeners = listener;
}
int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
@ -875,8 +870,7 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf)
{
assert(cf == COAP_FORMAT_LINK);
/* skip the first listener, gcoap itself (we skip /.well-known/core) */
gcoap_listener_t *listener = _coap_state.listeners->next;
gcoap_listener_t *listener = _coap_state.listeners;
char *out = (char *)buf;
size_t pos = 0;
@ -887,7 +881,7 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf)
ctx.flags = COAP_LINK_FLAG_INIT_RESLIST;
/* write payload */
while (listener) {
for (; listener != NULL; listener = listener->next) {
if (!listener->link_encoder) {
continue;
}
@ -912,8 +906,6 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf)
break;
}
}
listener = listener->next;
}
return (int)pos;

View File

@ -49,7 +49,7 @@ static gcoap_listener_t listener_second = {
.next = NULL
};
static const char *resource_list_str = "</act/switch>,</sensor/temp>,</test/info/all>,</second/part>";
static const char *resource_list_str = "</second/part>,</act/switch>,</sensor/temp>,</test/info/all>";
/*
* Client GET request success case. Test request generation.