Skip to content

Commit

Permalink
Block1: Only save all data if Observe request for subsequent re-regis…
Browse files Browse the repository at this point in the history
…tration
  • Loading branch information
mrdeep1 committed Feb 13, 2025
1 parent cea3dd4 commit 238694f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 21 additions & 3 deletions src/coap_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -2283,9 +2283,27 @@ coap_block_new_lg_crcv(coap_session_t *session, coap_pdu_t *pdu,
uint64_t state_token = STATE_TOKEN_FULL(++session->tx_token, 1);
size_t token_options = pdu->data ? (size_t)(pdu->data - pdu->token) :
pdu->used_size;
size_t data_len = lg_xmit ? lg_xmit->length :
pdu->data ?
pdu->used_size - (pdu->data - pdu->token) : 0;
size_t data_len;
int observe_action = -1;

if (lg_xmit) {
coap_opt_iterator_t opt_iter;
coap_opt_t *opt;

opt = coap_check_option(pdu, COAP_OPTION_OBSERVE, &opt_iter);

if (opt) {
observe_action = coap_decode_var_bytes(coap_opt_value(opt),
coap_opt_length(opt));
}
}
if (observe_action == COAP_OBSERVE_ESTABLISH) {
data_len = lg_xmit->length;
} else {
lg_xmit = NULL;
data_len = pdu->data ?
pdu->used_size - (pdu->data - pdu->token) : 0;
}

lg_crcv = coap_malloc_type(COAP_LG_CRCV, sizeof(coap_lg_crcv_t));

Expand Down
10 changes: 5 additions & 5 deletions src/coap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3569,7 +3569,7 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu
if (session->block_mode & COAP_BLOCK_USE_LIBCOAP) {
uint32_t block_mode = session->block_mode;

if (pdu->code == COAP_REQUEST_CODE_FETCH ||
if (observe ||
resource->flags & COAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY)
session->block_mode |= COAP_BLOCK_SINGLE_BODY;
if (coap_handle_request_put_block(context, session, pdu, response,
Expand Down Expand Up @@ -3617,10 +3617,10 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu
uint8_t buf[4];

coap_touch_observer(context, session, &pdu->actual_token);
coap_add_option_internal(response, COAP_OPTION_OBSERVE,
coap_encode_var_safe(buf, sizeof(buf),
resource->observe),
buf);
coap_insert_option(response, COAP_OPTION_OBSERVE,
coap_encode_var_safe(buf, sizeof(buf),
resource->observe),
buf);
}
} else if (observe_action == COAP_OBSERVE_CANCEL) {
coap_delete_observer_request(resource, session, &pdu->actual_token, pdu);
Expand Down

0 comments on commit 238694f

Please sign in to comment.