libcoap
libcoap copied to clipboard
Multi Client obs and server queue notify to client.
I have some question about service obs notify;
In my usage scenario:
- in client; multi client obs servcie resource;
- in service; add a resource that can be observed;
I have two questions:
- How to know that the current handler is triggered by coap _resource_notify_observers.
- How to know that all current observers have been notified.
I assume that you have read coap_observe(3). All this logic is based on RFC7641.
Calling coap_resource_notify_observers()
from within your server application will cause all client observers for that resource to receive an unsolicited response. These unsolicited responses can be of type NON or CON, which is configurable based on the the resource flag settings when configuring the resource to be observed (see coap_resource(3).
The only exception to an unsolicited response not being sent is if there is a previous unsolicited response of type CON that the client has not yet acknowledged with an ACK (i.e. they can be rate limited). A client observer in the server will be removed if the client does not respond at all with an ACK to CON unsolicited response, or the client responds with a RST.
So,the server can only assume that the unsolicited responses have been sent unless there is a client response failure. If NON is used to send the unsolicited response, there is no guarantee that he client has actually received and processed the unsolicited response.
The client has to register with the server that it wants to observe a resource (sometimes called a subscription). There is nothing stopping a client with registering for multiple resources. Note that registering multiple times for the same resource (and using same optional query) is considered as a refresh for the observe request by the server.
I used a queue to save all notify value. ; so I want to known when pop ele from queue, and notify next queue ele to the client observer; for example: queue have two value want to notify clients; and resource have two clients. in this case,:
- coap_resource_notify_observers and get_handler will be invoked, in the handler insert value to the response then one obs has been notified;
- if check clients remaining number > 0 then call coap_resource_notify_observers; if check clients remaining number == 0 then pop queue, notify next queue ele, call coap_resource_notify_observers;
coap_resource_notify_observers() will at the next call to coap_io_process() cause a pseudo request (a copy of the PDU used by the client to register the request) to call the appropriate request handler and then send on that unsolicited response, as filled in by the request handler. This is automatically repeated for every client registered for that resource.
So, whenever a resource has a new value, just call coap_resource_notify_observers() once for the updated resource.
Do you means that call coap_resource_notify_observers() before call coap_io_process()? and then after coap_io_process() all the obs will be notified; at this time resouce can reload new value fot next;
At the beginning, I want to make hole in coap_resource_t and get dirty status; your selution is good for me; thank for you help!
Do you means that call coap_resource_notify_observers() before call coap_io_process()? and then after coap_io_process() all the obs will be notified; at this time resource can reload new value for next;
Correct. You just need to check that you are not flooding the network with too much updating traffic.