net: lwm2m: correct packet pending process in lwm2m_send_message()
During the CoAP API change, the way packets were ref'd and then unref'd in order to stop the packet sending functions from releasing the net_pkts was changed and never updated in the LwM2M library. Let's use coap_pending_cycle() and coap_pending_clear() to do the ref/unref the same way as the coap-client samples in order to match the pending process with the current CoAP APIs. Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
This commit is contained in:
parent
d03ad43dbb
commit
db09596b1d
1 changed files with 14 additions and 11 deletions
|
@ -1032,41 +1032,44 @@ cleanup:
|
|||
int lwm2m_send_message(struct lwm2m_message *msg)
|
||||
{
|
||||
int ret;
|
||||
struct net_pkt *pkt;
|
||||
|
||||
if (!msg || !msg->ctx) {
|
||||
SYS_LOG_ERR("LwM2M message is invalid.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* protect the packet from being released inbetween net_app_send_pkt()
|
||||
* to coap_pending_cycle()
|
||||
*/
|
||||
pkt = msg->cpkt.pkt;
|
||||
net_pkt_ref(pkt);
|
||||
if (msg->type == COAP_TYPE_CON) {
|
||||
/*
|
||||
* Increase packet ref count to avoid being unref after
|
||||
* net_app_send_pkt()
|
||||
*/
|
||||
coap_pending_cycle(msg->pending);
|
||||
}
|
||||
|
||||
msg->send_attempts++;
|
||||
ret = net_app_send_pkt(&msg->ctx->net_app_ctx, msg->cpkt.pkt,
|
||||
&msg->ctx->net_app_ctx.default_ctx->remote,
|
||||
NET_SOCKADDR_MAX_SIZE, K_NO_WAIT, NULL);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
if (msg->type == COAP_TYPE_CON) {
|
||||
coap_pending_clear(msg->pending);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (msg->type == COAP_TYPE_CON) {
|
||||
/* don't re-queue the retransmit work on retransmits */
|
||||
if (msg->send_attempts > 1) {
|
||||
goto out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
coap_pending_cycle(msg->pending);
|
||||
k_delayed_work_submit(&msg->ctx->retransmit_work,
|
||||
msg->pending->timeout);
|
||||
} else {
|
||||
lwm2m_reset_message(msg, true);
|
||||
}
|
||||
|
||||
out:
|
||||
net_pkt_unref(pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue