qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject qpid-proton git commit: made terminal selectables produce idempotent final events
Date Wed, 21 Jan 2015 18:40:20 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 4546829be -> 2a784f41f


made terminal selectables produce idempotent final events


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/2a784f41
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/2a784f41
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/2a784f41

Branch: refs/heads/master
Commit: 2a784f41f9bdfc06e1c56542978f953898d6c0c8
Parents: 4546829
Author: Rafael Schloming <rhs@alum.mit.edu>
Authored: Wed Jan 21 13:40:10 2015 -0500
Committer: Rafael Schloming <rhs@alum.mit.edu>
Committed: Wed Jan 21 13:40:10 2015 -0500

----------------------------------------------------------------------
 proton-c/src/handlers/iohandler.c | 14 ++++++++------
 proton-c/src/reactor/reactor.c    | 22 ++++++++++++++++++----
 proton-c/src/tests/reactor.c      | 17 +++++++----------
 3 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2a784f41/proton-c/src/handlers/iohandler.c
----------------------------------------------------------------------
diff --git a/proton-c/src/handlers/iohandler.c b/proton-c/src/handlers/iohandler.c
index 02e0d0b..1983bd4 100644
--- a/proton-c/src/handlers/iohandler.c
+++ b/proton-c/src/handlers/iohandler.c
@@ -69,12 +69,14 @@ static void pn_iodispatch(pn_iohandler_t *handler, pn_event_t *event)
{
   case PN_SELECTABLE_UPDATED:
     {
       pn_selectable_t *sel = (pn_selectable_t *) pn_event_context(event);
-      if (pn_selectable_is_terminal(sel)) {
-        pn_selector_remove(selector, sel);
-        pn_selectable_release(sel);
-      } else {
-        pn_selector_update(selector, sel);
-      }
+      pn_selector_update(selector, sel);
+    }
+    break;
+  case PN_SELECTABLE_FINAL:
+    {
+      pn_selectable_t *sel = (pn_selectable_t *) pn_event_context(event);
+      pn_selector_remove(selector, sel);
+      pn_selectable_release(sel);
     }
     break;
   case PN_CONNECTION_LOCAL_OPEN:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2a784f41/proton-c/src/reactor/reactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/reactor.c b/proton-c/src/reactor/reactor.c
index 536bb11..80b5762 100644
--- a/proton-c/src/reactor/reactor.c
+++ b/proton-c/src/reactor/reactor.c
@@ -141,9 +141,11 @@ pn_list_t *pn_reactor_children(pn_reactor_t *reactor) {
 
 static void pni_selectable_release(pn_selectable_t *selectable) {
   pn_reactor_t *reactor = (pn_reactor_t *) pni_selectable_get_context(selectable);
-  pn_collector_put(reactor->collector, PN_OBJECT, selectable, PN_SELECTABLE_FINAL);
-  pn_list_remove(reactor->children, selectable);
-  reactor->selectables--;
+  pn_incref(selectable);
+  if (pn_list_remove(reactor->children, selectable)) {
+    reactor->selectables--;
+  }
+  pn_decref(selectable);
 }
 
 pn_selectable_t *pn_reactor_selectable(pn_reactor_t *reactor) {
@@ -159,9 +161,21 @@ pn_selectable_t *pn_reactor_selectable(pn_reactor_t *reactor) {
   return sel;
 }
 
+static void *pni_terminated = NULL;
+
+#define PNI_TERMINATED ((pn_handle_t) &pni_terminated)
+
 void pn_reactor_update(pn_reactor_t *reactor, pn_selectable_t *selectable) {
   assert(reactor);
-  pn_collector_put(reactor->collector, PN_OBJECT, selectable, PN_SELECTABLE_UPDATED);
+  pn_record_t *record = pn_selectable_attachments(selectable);
+  if (!pn_record_has(record, PNI_TERMINATED)) {
+    if (pn_selectable_is_terminal(selectable)) {
+      pn_record_def(record, PNI_TERMINATED, PN_VOID);
+      pn_collector_put(reactor->collector, PN_OBJECT, selectable, PN_SELECTABLE_FINAL);
+    } else {
+      pn_collector_put(reactor->collector, PN_OBJECT, selectable, PN_SELECTABLE_UPDATED);
+    }
+  }
 }
 
 static void pni_reactor_dispatch_pre(pn_reactor_t *reactor, pn_event_t *event) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2a784f41/proton-c/src/tests/reactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/reactor.c b/proton-c/src/tests/reactor.c
index 5c30b1e..f5701fa 100644
--- a/proton-c/src/tests/reactor.c
+++ b/proton-c/src/tests/reactor.c
@@ -137,8 +137,7 @@ static void test_reactor_handler_run(void) {
   pn_handler_t *th = test_handler(reactor, events);
   pn_handler_add(handler, th);
   pn_reactor_run(reactor);
-  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_UPDATED,
-         PN_SELECTABLE_FINAL, PN_REACTOR_FINAL, END);
+  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL,
PN_REACTOR_FINAL, END);
   pn_free(reactor);
   pn_free(th);
   pn_free(events);
@@ -152,8 +151,7 @@ static void test_reactor_handler_run_free(void) {
   pn_list_t *events = pn_list(PN_VOID, 0);
   pn_handler_add(handler, test_handler(reactor, events));
   pn_reactor_run(reactor);
-  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_UPDATED,
-         PN_SELECTABLE_FINAL, PN_REACTOR_FINAL, END);
+  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL,
PN_REACTOR_FINAL, END);
   pn_reactor_free(reactor);
   pn_free(events);
 }
@@ -169,8 +167,8 @@ static void test_reactor_connection(void) {
   pn_list_t *revents = pn_list(PN_VOID, 0);
   pn_handler_add(root, test_handler(reactor, revents));
   pn_reactor_run(reactor);
-  expect(revents, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_UPDATED,
-         PN_SELECTABLE_FINAL, PN_REACTOR_FINAL, END);
+  expect(revents, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL,
PN_REACTOR_FINAL,
+         END);
   expect(cevents, PN_CONNECTION_INIT, END);
   pn_reactor_free(reactor);
   pn_handler_free(tch);
@@ -420,8 +418,7 @@ static void test_reactor_schedule(void) {
   pn_reactor_run(reactor);
   pn_reactor_free(reactor);
   expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_REACTOR_QUIESCED,
-         PN_TIMER_TASK, PN_SELECTABLE_UPDATED, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL,
PN_REACTOR_FINAL,
-         END);
+         PN_TIMER_TASK, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL, PN_REACTOR_FINAL, END);
   pn_free(events);
 }
 
@@ -436,8 +433,8 @@ static void test_reactor_schedule_handler(void) {
   pn_reactor_run(reactor);
   pn_reactor_free(reactor);
   pn_handler_free(th);
-  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_REACTOR_QUIESCED,
-         PN_SELECTABLE_UPDATED, PN_SELECTABLE_UPDATED, PN_SELECTABLE_FINAL, PN_REACTOR_FINAL,
END);
+  expect(events, PN_REACTOR_INIT, PN_SELECTABLE_INIT, PN_SELECTABLE_UPDATED, PN_REACTOR_QUIESCED,
PN_SELECTABLE_UPDATED,
+         PN_SELECTABLE_FINAL, PN_REACTOR_FINAL, END);
   expect(tevents, PN_TIMER_TASK, END);
   pn_free(events);
   pn_free(tevents);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message