803 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

 / 详情

lwm2m connection couldn't be set within first second

已完成
创建于  
2021-01-05 03:54

该问题是怎么引起的

In the lwm2m demo project, the function prv_register() is used to send the registration for a single server. However, the function transaction_send(), which is called by the function prv_register() to perform send operation, will cause retransfer due to the fact that the time do not reach the first second in some reboot occasion as shown in the https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/lwm2m/core/transaction.c?_from=gitee_search#L446. The variable tv_sec may be zero if just reboot and still in the time of the first second.
And I'm not sure why this time judgment is needed.

重现步骤

Build and run lwm2m. Please pay attention that the occasion is not always could be observed.

报错信息

No errors. But the process and the performance will be affected.

评论 (1)

SilentDawn 创建了任务
SilentDawn 关联仓库设置为LiteOS/LiteOS
SilentDawn 修改了描述
展开全部操作日志

@SilentDawn
The variable tv_sec may be zero if just reboot and still in the time of the first second.
And I'm not sure why this time judgment is needed.

Yes, when client device has rebooted, the tv_sec must be zero.
In the registration process, the first time ack_received is null:
if (!transacP->ack_received)
{
long unsigned timeout = 0;

    if (0 == transacP->retrans_counter) --> and we are here, the retrans_counter is zero
    {
        time_t tv_sec = lwm2m_gettime();  --> get local devie time(s)
        if (tv_sec)          --> if tv_sec >= 1, set the counter flag retrans_counter
        {
            transacP->retrans_time = tv_sec + COAP_RESPONSE_TIMEOUT;
            transacP->retrans_counter = 1;
            timeout = 0;
        }
        else                --> if tv_sec < 1, do not set counter flag
        {
            maxRetriesReached = true;
        }


    if (COAP_MAX_RETRANSMIT + 1 >= transacP->retrans_counter)
    {
        ret = lwm2m_buffer_send(transacP->peerH, transacP->buffer, transacP->buffer_len, contextP->userData); --> try to send again
        output_buffer(stderr, (uint8_t *)(transacP->buffer), transacP->buffer_len, 0);
        transacP->retrans_time += timeout;
        LOG_ARG("send result is %d, retrans_counter:%d", ret, transacP->retrans_counter);
        transacP->retrans_counter += 1;                                --> set counter flag here,when retrans_counter is zero, the next time will not go to branch:if (0 == transacP->retrans_counter) 

        UNUSEX(ret);
    }

It is obviously that, when tv_sec < 1, there is no problem; but if when tv_sec > 1, set retrans_time for transaction_step to remove some transcation from linked list.

bing 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS

搜索帮助