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:
Michael Scott 2018-01-30 13:39:34 -08:00 committed by Jukka Rissanen
commit db09596b1d

View file

@ -1032,41 +1032,44 @@ cleanup:
int lwm2m_send_message(struct lwm2m_message *msg) int lwm2m_send_message(struct lwm2m_message *msg)
{ {
int ret; int ret;
struct net_pkt *pkt;
if (!msg || !msg->ctx) { if (!msg || !msg->ctx) {
SYS_LOG_ERR("LwM2M message is invalid."); SYS_LOG_ERR("LwM2M message is invalid.");
return -EINVAL; return -EINVAL;
} }
/* protect the packet from being released inbetween net_app_send_pkt() if (msg->type == COAP_TYPE_CON) {
* to coap_pending_cycle() /*
*/ * Increase packet ref count to avoid being unref after
pkt = msg->cpkt.pkt; * net_app_send_pkt()
net_pkt_ref(pkt); */
coap_pending_cycle(msg->pending);
}
msg->send_attempts++; msg->send_attempts++;
ret = net_app_send_pkt(&msg->ctx->net_app_ctx, msg->cpkt.pkt, ret = net_app_send_pkt(&msg->ctx->net_app_ctx, msg->cpkt.pkt,
&msg->ctx->net_app_ctx.default_ctx->remote, &msg->ctx->net_app_ctx.default_ctx->remote,
NET_SOCKADDR_MAX_SIZE, K_NO_WAIT, NULL); NET_SOCKADDR_MAX_SIZE, K_NO_WAIT, NULL);
if (ret < 0) { if (ret < 0) {
goto out; if (msg->type == COAP_TYPE_CON) {
coap_pending_clear(msg->pending);
}
return ret;
} }
if (msg->type == COAP_TYPE_CON) { if (msg->type == COAP_TYPE_CON) {
/* don't re-queue the retransmit work on retransmits */
if (msg->send_attempts > 1) { if (msg->send_attempts > 1) {
goto out; return 0;
} }
coap_pending_cycle(msg->pending);
k_delayed_work_submit(&msg->ctx->retransmit_work, k_delayed_work_submit(&msg->ctx->retransmit_work,
msg->pending->timeout); msg->pending->timeout);
} else { } else {
lwm2m_reset_message(msg, true); lwm2m_reset_message(msg, true);
} }
out:
net_pkt_unref(pkt);
return ret; return ret;
} }