Commit a14f0830 authored by Seppo Takalo's avatar Seppo Takalo Committed by Mahesh Mahadevan
Browse files

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: default avatarSeppo Takalo <seppo.takalo@nordicsemi.no>
parent 623a1ffd
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -60,24 +60,16 @@ static int receive(int sock, void *buf, size_t max_len, int flags,
	return err;
}

static void reset_block_contexts(struct coap_client_internal_request *request)
{
	request->recv_blk_ctx.block_size = 0;
	request->recv_blk_ctx.total_size = 0;
	request->recv_blk_ctx.current = 0;

	request->send_blk_ctx.block_size = 0;
	request->send_blk_ctx.total_size = 0;
	request->send_blk_ctx.current = 0;
}

static void reset_internal_request(struct coap_client_internal_request *request)
{
	request->offset = 0;
	request->last_id = 0;
	request->last_response_id = -1;
	request->request_ongoing = false;
	reset_block_contexts(request);
	request->is_observe = false;
	request->pending.timeout = 0;
	request->recv_blk_ctx = (struct coap_block_context){ 0 };
	request->send_blk_ctx = (struct coap_block_context){ 0 };
}

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
	}
fail:
	if (ret < 0 || !internal_req->is_observe) {
		internal_req->request_ongoing = false;
		reset_internal_request(internal_req);
	}
	return ret;
}