mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-22 15:25:14 +03:00
Block1: Only save all data if Observe request for subsequent re-registration
This commit is contained in:
1 parent
cea3dd449b
commit
238694fe1a
2 files changed
+26
-8
No files matched your search
+21
-3
@@ -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));
|
||||
|
||||
|
||||
+5
-5
@@ -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,
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user