Skip to content

Commit

Permalink
block handling: Update lg_crcv->last_used when sending Block1
Browse files Browse the repository at this point in the history
This prevents premature de-allocation of the lg_crcv when large
files are getting uploaded.
  • Loading branch information
mrdeep1 committed Jul 12, 2024
1 parent bfdbdc3 commit 8ccce9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/coap3/coap_block_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct coap_l_block1_t {
coap_binary_t *app_token; /**< original PDU token */
uint64_t state_token; /**< state token */
size_t bert_size; /**< size of last BERT block */
coap_lg_crcv_t *lg_crcv; /**< The lg_crcv associated with this blocked xmit */
uint32_t count; /**< the number of packets sent for payload */
} coap_l_block1_t;

Expand Down
24 changes: 14 additions & 10 deletions src/coap_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,9 @@ coap_block_new_lg_crcv(coap_session_t *session, coap_pdu_t *pdu,
coap_remove_option(&lg_crcv->pdu, COAP_OPTION_BLOCK1);
}

if (lg_xmit)
lg_xmit->b.b1.lg_crcv = lg_crcv;

return lg_crcv;
}

Expand Down Expand Up @@ -3326,6 +3329,10 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent,
size_t chunk = (size_t)1 << (lg_xmit->blk_size + 4);
coap_block_b_t block;

lg_crcv = lg_xmit->b.b1.lg_crcv;
if (lg_crcv)
coap_ticks(&lg_crcv->last_used);

if (COAP_RESPONSE_CLASS(rcvd->code) == 2 &&
coap_get_block_b(session, rcvd, lg_xmit->option, &block)) {

Expand Down Expand Up @@ -3391,7 +3398,7 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent,

if (lg_xmit->pdu.code == COAP_REQUEST_CODE_FETCH) {
/* Need to handle Observe for large FETCH */
LL_FOREACH(session->lg_crcv, lg_crcv) {
if (lg_crcv) {
if (coap_binary_equal(lg_xmit->b.b1.app_token, lg_crcv->app_token)) {
coap_bin_const_t *new_token;
coap_bin_const_t ctoken = { len, buf };
Expand Down Expand Up @@ -3571,15 +3578,12 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent,
/* There has been an internal error of some sort */
rcvd->code = COAP_RESPONSE_CODE(500);
lg_xmit_finished:
if (session->lg_crcv) {
LL_FOREACH(session->lg_crcv, lg_crcv) {
if (STATE_TOKEN_BASE(lg_xmit->b.b1.state_token) ==
STATE_TOKEN_BASE(lg_crcv->state_token)) {
/* In case of observe */
lg_crcv->state_token = lg_xmit->b.b1.state_token;
lg_crcv->retry_counter = lg_xmit->b.b1.count;
break;
}
if (lg_crcv) {
if (STATE_TOKEN_BASE(lg_xmit->b.b1.state_token) ==
STATE_TOKEN_BASE(lg_crcv->state_token)) {
/* In case of observe */
lg_crcv->state_token = lg_xmit->b.b1.state_token;
lg_crcv->retry_counter = lg_xmit->b.b1.count;
}
}
if (!lg_crcv) {
Expand Down

0 comments on commit 8ccce9f

Please sign in to comment.