Handle block-wise transfer in observer notifications

This commit is contained in:
Johan Liseborn 2018-02-23 09:41:30 +01:00
parent 22e131bc6d
commit 9aaba942e1
1 changed files with 15 additions and 2 deletions

View File

@ -259,16 +259,18 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath)
/* prepare response */
notification->mid = transaction->mid;
int32_t new_offset = 0;
/* Either old style get_handler or the full handler */
if(coap_call_handlers(request, notification, transaction->message +
COAP_MAX_HEADER_SIZE, COAP_MAX_CHUNK_SIZE,
NULL) > 0) {
&new_offset) > 0) {
LOG_DBG("Notification on new handlers\n");
} else {
if(resource != NULL) {
resource->get_handler(request, notification,
transaction->message + COAP_MAX_HEADER_SIZE,
COAP_MAX_CHUNK_SIZE, NULL);
COAP_MAX_CHUNK_SIZE, &new_offset);
} else {
/* What to do here? */
notification->code = BAD_REQUEST_4_00;
@ -282,6 +284,17 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath)
}
coap_set_token(notification, obs->token, obs->token_len);
if(new_offset != 0) {
coap_set_header_block2(notification,
0,
new_offset != -1,
COAP_MAX_BLOCK_SIZE);
coap_set_payload(notification,
notification->payload,
MIN(notification->payload_len,
COAP_MAX_BLOCK_SIZE));
}
transaction->message_len =
coap_serialize_message(notification, transaction->message);