Skip to content

Commit a14f083

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: lib: coap_client: Use reset_internal_request() instead of flagging
It is error prone to flag separate booleans, so try to use reset_internal_request() every time we release the internal request structure. Also refactor the reset_internal_request() so that we reset the timeout value so it does not trigger again. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 623a1ff commit a14f083

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,16 @@ static int receive(int sock, void *buf, size_t max_len, int flags,
6060
return err;
6161
}
6262

63-
static void reset_block_contexts(struct coap_client_internal_request *request)
64-
{
65-
request->recv_blk_ctx.block_size = 0;
66-
request->recv_blk_ctx.total_size = 0;
67-
request->recv_blk_ctx.current = 0;
68-
69-
request->send_blk_ctx.block_size = 0;
70-
request->send_blk_ctx.total_size = 0;
71-
request->send_blk_ctx.current = 0;
72-
}
73-
7463
static void reset_internal_request(struct coap_client_internal_request *request)
7564
{
7665
request->offset = 0;
7766
request->last_id = 0;
7867
request->last_response_id = -1;
7968
request->request_ongoing = false;
80-
reset_block_contexts(request);
69+
request->is_observe = false;
70+
request->pending.timeout = 0;
71+
request->recv_blk_ctx = (struct coap_block_context){ 0 };
72+
request->send_blk_ctx = (struct coap_block_context){ 0 };
8173
}
8274

8375
static int coap_client_schedule_poll(struct coap_client *client, int sock,
@@ -912,7 +904,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet
912904
}
913905
fail:
914906
if (ret < 0 || !internal_req->is_observe) {
915-
internal_req->request_ongoing = false;
907+
reset_internal_request(internal_req);
916908
}
917909
return ret;
918910
}

0 commit comments

Comments
 (0)