Author Topic: LWMesh NWK_DataReq Infinite Loop Condition  (Read 1182 times)

0 Members and 1 Guest are viewing this topic.

Offline friendly_giantTopic starter

  • Newbie
  • Posts: 3
  • Country: us
LWMesh NWK_DataReq Infinite Loop Condition
« on: June 15, 2017, 08:49:18 pm »
I have encountered my device enter into an infinite loop when NWK_DataReq is called for the same req twice without clearing it from the queue. I have added the following catch to prevent this:
Code: [Select]
void NWK_DataReq(NWK_DataReq_t *req)
{
req->state = NWK_DATA_REQ_STATE_INITIAL;
req->status = NWK_SUCCESS_STATUS;
req->frame = NULL;

nwkIb.lock++;

if (NULL == nwkDataReqQueue) {
req->next = NULL;
nwkDataReqQueue = req;
}
else if (nwkDataReqQueue==req){ //catch duplicate req
printf("double message \r\n");
}
else{
req->next = nwkDataReqQueue;
nwkDataReqQueue = req;
}
}

What I don't know yet is why this is happening, it seems that there shouldn't be a condition where NWK_DataReq is called twice on the same req frame. Also, would like input on whether it is dangerous to put this catch in there, whether I might lose data.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: LWMesh NWK_DataReq Infinite Loop Condition
« Reply #1 on: June 15, 2017, 09:16:26 pm »
This is documented and done on purpose. You should never call this request twice on the same structure before previous confirmation is called.

The infinite loop is a clear and cheap indication that something is wrong with your program. Your high level logic should prevent calls like this.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: LWMesh NWK_DataReq Infinite Loop Condition
« Reply #2 on: June 15, 2017, 10:05:17 pm »
Also, you are only verifying that your request is not the same as the last request. This check will not catch things like: ReqA, ReqB, ReqA again.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf