You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2015/01/22 21:38:43 UTC

qpid-proton git commit: added API to allow handling of error events like POLLHUP, POLLERR

Repository: qpid-proton
Updated Branches:
  refs/heads/master 4f11a90e9 -> 15e0ae96a


added API to allow handling of error events like POLLHUP, POLLERR


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

Branch: refs/heads/master
Commit: 15e0ae96a7e884439c1eda93089e16e0d3128231
Parents: 4f11a90
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Thu Jan 22 15:38:16 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Thu Jan 22 15:38:16 2015 -0500

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py     |  1 +
 proton-c/include/proton/event.h                 |  1 +
 proton-c/include/proton/selectable.h            |  8 ++++++++
 proton-c/include/proton/selector.h              |  1 +
 proton-c/src/events/event.c                     |  2 ++
 proton-c/src/handlers/iohandler.c               |  3 +++
 proton-c/src/posix/selector.c                   |  3 +--
 proton-c/src/reactor/connection.c               |  7 +++++++
 proton-c/src/selectable.c                       | 20 ++++++++++++++++++++
 .../org/apache/qpid/proton/engine/Event.java    |  1 +
 proton-j/src/main/resources/cengine.py          |  1 +
 11 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index d07fb6f..03bff98 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3363,6 +3363,7 @@ class Event(Wrapper, EventBase):
   SELECTABLE_READABLE = EventType(PN_SELECTABLE_READABLE, "on_selectable_readable")
   SELECTABLE_WRITABLE = EventType(PN_SELECTABLE_WRITABLE, "on_selectable_writable")
   SELECTABLE_EXPIRED = EventType(PN_SELECTABLE_EXPIRED, "on_selectable_expired")
+  SELECTABLE_ERROR = EventType(PN_SELECTABLE_ERROR, "on_selectable_error")
   SELECTABLE_FINAL = EventType(PN_SELECTABLE_FINAL, "on_selectable_final")
 
   @staticmethod

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/include/proton/event.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/event.h b/proton-c/include/proton/event.h
index a4d3d52..404a871 100644
--- a/proton-c/include/proton/event.h
+++ b/proton-c/include/proton/event.h
@@ -293,6 +293,7 @@ typedef enum {
   PN_SELECTABLE_UPDATED,
   PN_SELECTABLE_READABLE,
   PN_SELECTABLE_WRITABLE,
+  PN_SELECTABLE_ERROR,
   PN_SELECTABLE_EXPIRED,
   PN_SELECTABLE_FINAL
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/include/proton/selectable.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/selectable.h b/proton-c/include/proton/selectable.h
index ac0416c..07cb212 100644
--- a/proton-c/include/proton/selectable.h
+++ b/proton-c/include/proton/selectable.h
@@ -96,6 +96,7 @@ PN_EXTERN pn_selectable_t *pn_selectable(void);
 PN_EXTERN void pn_selectable_on_readable(pn_selectable_t *sel, void (*readable)(pn_selectable_t *));
 PN_EXTERN void pn_selectable_on_writable(pn_selectable_t *sel, void (*writable)(pn_selectable_t *));
 PN_EXTERN void pn_selectable_on_expired(pn_selectable_t *sel, void (*expired)(pn_selectable_t *));
+PN_EXTERN void pn_selectable_on_error(pn_selectable_t *sel, void (*error)(pn_selectable_t *));
 PN_EXTERN void pn_selectable_on_release(pn_selectable_t *sel, void (*release)(pn_selectable_t *));
 PN_EXTERN void pn_selectable_on_finalize(pn_selectable_t *sel, void (*finalize)(pn_selectable_t *));
 
@@ -166,6 +167,13 @@ PN_EXTERN void pn_selectable_readable(pn_selectable_t *selectable);
 PN_EXTERN void pn_selectable_writable(pn_selectable_t *selectable);
 
 /**
+ * Notify a selectable that there is an error on the file descriptor.
+ *
+ * @param[in] selectable a selectable object
+ */
+PN_EXTERN void pn_selectable_error(pn_selectable_t *selectable);
+
+/**
  * Notify a selectable that its deadline has expired.
  *
  * @param[in] selectable a selectable object

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/include/proton/selector.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/selector.h b/proton-c/include/proton/selector.h
index d0cc352..c942393 100644
--- a/proton-c/include/proton/selector.h
+++ b/proton-c/include/proton/selector.h
@@ -33,6 +33,7 @@ extern "C" {
 #define PN_READABLE (1)
 #define PN_WRITABLE (2)
 #define PN_EXPIRED (4)
+#define PN_ERROR (8)
 
 pn_selector_t *pni_selector(void);
 PN_EXTERN void pn_selector_free(pn_selector_t *selector);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/src/events/event.c
----------------------------------------------------------------------
diff --git a/proton-c/src/events/event.c b/proton-c/src/events/event.c
index 54ef92f..00ca8ff 100644
--- a/proton-c/src/events/event.c
+++ b/proton-c/src/events/event.c
@@ -330,6 +330,8 @@ const char *pn_event_type_name(pn_event_type_t type)
     return "PN_SELECTABLE_READABLE";
   case PN_SELECTABLE_WRITABLE:
     return "PN_SELECTABLE_WRITABLE";
+  case PN_SELECTABLE_ERROR:
+    return "PN_SELECTABLE_ERROR";
   case PN_SELECTABLE_EXPIRED:
     return "PN_SELECTABLE_EXPIRED";
   case PN_SELECTABLE_FINAL:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/src/handlers/iohandler.c
----------------------------------------------------------------------
diff --git a/proton-c/src/handlers/iohandler.c b/proton-c/src/handlers/iohandler.c
index 1983bd4..be976e5 100644
--- a/proton-c/src/handlers/iohandler.c
+++ b/proton-c/src/handlers/iohandler.c
@@ -42,6 +42,9 @@ void pni_handle_quiesced(pn_reactor_t *reactor, pn_selector_t *selector) {
     if (events & PN_EXPIRED) {
       pn_selectable_expired(sel);
     }
+    if (events & PN_ERROR) {
+      pn_selectable_error(sel);
+    }
   }
   pn_reactor_yield(reactor);
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/src/posix/selector.c
----------------------------------------------------------------------
diff --git a/proton-c/src/posix/selector.c b/proton-c/src/posix/selector.c
index db82f11..079df07 100644
--- a/proton-c/src/posix/selector.c
+++ b/proton-c/src/posix/selector.c
@@ -186,8 +186,7 @@ pn_selectable_t *pn_selector_next(pn_selector_t *selector, int *events)
     if ((pfd->revents & POLLERR) ||
         (pfd->revents & POLLHUP) ||
         (pfd->revents & POLLNVAL)) {
-      ev |= PN_READABLE;
-      ev |= PN_WRITABLE;
+      ev |= PN_ERROR;
     }
     if (pfd->revents & POLLOUT) {
       ev |= PN_WRITABLE;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/src/reactor/connection.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/connection.c b/proton-c/src/reactor/connection.c
index 86b84e9..e5233fc 100644
--- a/proton-c/src/reactor/connection.c
+++ b/proton-c/src/reactor/connection.c
@@ -173,6 +173,12 @@ static void pni_connection_writable(pn_selectable_t *sel)
   }
 }
 
+static void pni_connection_error(pn_selectable_t *sel) {
+  pn_reactor_t *reactor = (pn_reactor_t *) pni_selectable_get_context(sel);
+  pn_selectable_terminate(sel);
+  pn_reactor_update(reactor, sel);
+}
+
 static void pni_connection_expired(pn_selectable_t *sel) {}
 
 static void pni_connection_finalize(pn_selectable_t *sel) {
@@ -189,6 +195,7 @@ pn_selectable_t *pn_reactor_selectable_transport(pn_reactor_t *reactor, pn_socke
   pn_selectable_set_fd(sel, sock);
   pn_selectable_on_readable(sel, pni_connection_readable);
   pn_selectable_on_writable(sel, pni_connection_writable);
+  pn_selectable_on_error(sel, pni_connection_error);
   pn_selectable_on_expired(sel, pni_connection_expired);
   pn_selectable_on_finalize(sel, pni_connection_finalize);
   pn_record_t *record = pn_selectable_attachments(sel);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-c/src/selectable.c
----------------------------------------------------------------------
diff --git a/proton-c/src/selectable.c b/proton-c/src/selectable.c
index 94856ab..88a60f7 100644
--- a/proton-c/src/selectable.c
+++ b/proton-c/src/selectable.c
@@ -46,6 +46,7 @@ struct pn_selectable_t {
   pn_record_t *attachments;
   void (*readable)(pn_selectable_t *);
   void (*writable)(pn_selectable_t *);
+  void (*error)(pn_selectable_t *);
   void (*expired)(pn_selectable_t *);
   void (*release) (pn_selectable_t *);
   void (*finalize)(pn_selectable_t *);
@@ -64,6 +65,7 @@ void pn_selectable_initialize(pn_selectable_t *sel)
   sel->attachments = pn_record();
   sel->readable = NULL;
   sel->writable = NULL;
+  sel->error = NULL;
   sel->expired = NULL;
   sel->release = NULL;
   sel->finalize = NULL;
@@ -135,6 +137,11 @@ void pn_selectable_on_writable(pn_selectable_t *sel, void (*writable)(pn_selecta
   sel->writable = writable;
 }
 
+void pn_selectable_on_error(pn_selectable_t *sel, void (*error)(pn_selectable_t *)) {
+  assert(sel);
+  sel->error = error;
+}
+
 void pn_selectable_on_expired(pn_selectable_t *sel, void (*expired)(pn_selectable_t *)) {
   assert(sel);
   sel->expired = expired;
@@ -206,6 +213,14 @@ void pn_selectable_writable(pn_selectable_t *selectable)
   }
 }
 
+void pn_selectable_error(pn_selectable_t *selectable)
+{
+  assert(selectable);
+  if (selectable->error) {
+    selectable->error(selectable);
+  }
+}
+
 void pn_selectable_expired(pn_selectable_t *selectable)
 {
   assert(selectable);
@@ -259,6 +274,10 @@ static void pni_writable(pn_selectable_t *selectable) {
   pn_collector_put(selectable->collector, PN_OBJECT, selectable, PN_SELECTABLE_WRITABLE);
 }
 
+static void pni_error(pn_selectable_t *selectable) {
+  pn_collector_put(selectable->collector, PN_OBJECT, selectable, PN_SELECTABLE_ERROR);
+}
+
 static void pni_expired(pn_selectable_t *selectable) {
   pn_collector_put(selectable->collector, PN_OBJECT, selectable, PN_SELECTABLE_EXPIRED);
 }
@@ -272,6 +291,7 @@ void pn_selectable_collect(pn_selectable_t *selectable, pn_collector_t *collecto
   if (collector) {
     pn_selectable_on_readable(selectable, pni_readable);
     pn_selectable_on_writable(selectable, pni_writable);
+    pn_selectable_on_error(selectable, pni_error);
     pn_selectable_on_expired(selectable, pni_expired);
   }
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
index ebbf648..ddb6937 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
@@ -75,6 +75,7 @@ public interface Event
         SELECTABLE_READABLE,
         SELECTABLE_WRITABLE,
         SELECTABLE_EXPIRED,
+        SELECTABLE_ERROR,
         SELECTABLE_FINAL
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/15e0ae96/proton-j/src/main/resources/cengine.py
----------------------------------------------------------------------
diff --git a/proton-j/src/main/resources/cengine.py b/proton-j/src/main/resources/cengine.py
index 69fe4dd..c7b6a7f 100644
--- a/proton-j/src/main/resources/cengine.py
+++ b/proton-j/src/main/resources/cengine.py
@@ -990,6 +990,7 @@ PN_SELECTABLE_UPDATED = Event.Type.SELECTABLE_UPDATED
 PN_SELECTABLE_READABLE = Event.Type.SELECTABLE_READABLE
 PN_SELECTABLE_WRITABLE = Event.Type.SELECTABLE_WRITABLE
 PN_SELECTABLE_EXPIRED = Event.Type.SELECTABLE_EXPIRED
+PN_SELECTABLE_ERROR = Event.Type.SELECTABLE_ERROR
 PN_SELECTABLE_FINAL = Event.Type.SELECTABLE_FINAL
 
 def pn_collector():


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