Merge pull request #304 from superjudge/fix_observer
Fix observer and block-wise transfer interaction
This commit is contained in:
commit
9a6bbdcb5c
@ -70,7 +70,6 @@ static int invoke_coap_resource_service(coap_message_t *request,
|
||||
/*---------------------------------------------------------------------------*/
|
||||
LIST(coap_handlers);
|
||||
LIST(coap_resource_services);
|
||||
LIST(coap_resource_periodic_services);
|
||||
static uint8_t is_initialized = 0;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -373,7 +372,6 @@ coap_engine_init(void)
|
||||
|
||||
list_init(coap_handlers);
|
||||
list_init(coap_resource_services);
|
||||
list_init(coap_resource_periodic_services);
|
||||
|
||||
coap_activate_resource(&res_well_known_core, ".well-known/core");
|
||||
|
||||
@ -404,7 +402,6 @@ coap_activate_resource(coap_resource_t *resource, const char *path)
|
||||
&& resource->periodic->periodic_handler
|
||||
&& resource->periodic->period) {
|
||||
LOG_DBG("Periodic resource: %p (%s)\n", resource->periodic, path);
|
||||
list_add(coap_resource_periodic_services, resource->periodic);
|
||||
periodic = resource->periodic;
|
||||
coap_timer_set_callback(&periodic->periodic_timer, process_callback);
|
||||
coap_timer_set_user_data(&periodic->periodic_timer, resource);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user