aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-18 16:57:12 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-05-18 16:57:12 +0200
commit9eb56fc592c6e2c305a0fbcc69499271ac034236 (patch)
treeb04ef562218ae5aa169f0c7a5c21e0753efd0557
parent8abd9262e343aec71e07388bdf829d4f76d6529e (diff)
Fix a bug in subscribers counting
To avoid as much as possible allocation/deallocation when possible sequences of subscribe/unsubscribe are encountered, the watch strucutre of events is destroyed only when either the event or the client is destroyed. This commit fixes a bad handling in the count of active subscribers. Change-Id: I3f240e69c3b21356ff07f584fe9bfb578d46732b Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-evt.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/afb-evt.c b/src/afb-evt.c
index 88b6d603..7b7ce4f3 100644
--- a/src/afb-evt.c
+++ b/src/afb-evt.c
@@ -28,6 +28,7 @@
#include <afb/afb-event-itf.h>
#include "afb-evt.h"
+#include "verbose.h"
struct afb_evt_watch;
@@ -173,10 +174,11 @@ static int evt_push(struct afb_evt_event *evt, struct json_object *obj)
while(watch) {
listener = watch->listener;
assert(listener->itf->push != NULL);
- if (watch->activity != 0)
+ if (watch->activity != 0) {
listener->itf->push(listener->closure, evt->name, evt->id, json_object_get(obj));
+ result++;
+ }
watch = watch->next_by_event;
- result++;
}
pthread_mutex_unlock(&evt->mutex);
json_object_put(obj);
@@ -480,7 +482,6 @@ int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_event eve
watch = listener->watchs;
while(watch != NULL) {
if (watch->event == evt) {
- /* found: remove it */
if (watch->activity != 0) {
watch->activity--;
if (watch->activity == 0 && listener->itf->remove != NULL)