You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2020/04/23 01:56:37 UTC

[qpid-proton] branch master updated: PROTON-2195: Finalise the proactor API around pn_event_batch_t - Move pn_event_batch_t entirely into libqpid-proton-proactor - Make the pn_event_batch_t implementation private - Removed pn_event_batch_connection_driver() API as it is not used at all and can't be used for anything.

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/master by this push:
     new ae06b41  PROTON-2195: Finalise the proactor API around pn_event_batch_t - Move pn_event_batch_t entirely into libqpid-proton-proactor - Make the pn_event_batch_t implementation private - Removed pn_event_batch_connection_driver() API as it is not used at all   and can't be used for anything.
ae06b41 is described below

commit ae06b4180e924b392e1b816f97aada8591255b5a
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Wed Apr 22 13:34:51 2020 -0400

    PROTON-2195: Finalise the proactor API around pn_event_batch_t
    - Move pn_event_batch_t entirely into libqpid-proton-proactor
    - Make the pn_event_batch_t implementation private
    - Removed pn_event_batch_connection_driver() API as it is not used at all
      and can't be used for anything.
---
 c/include/proton/connection_driver.h |  7 -------
 c/include/proton/event.h             | 32 --------------------------------
 c/include/proton/proactor.h          | 12 ++++++++++++
 c/include/proton/types.h             | 13 +++++++++++++
 c/src/core/connection_driver.c       | 18 ++----------------
 c/src/core/event.c                   |  4 ----
 c/src/proactor/libuv.c               | 15 ++++++++++++---
 c/src/proactor/proactor-internal.c   |  4 ++++
 c/src/proactor/proactor-internal.h   |  8 ++++++++
 9 files changed, 51 insertions(+), 62 deletions(-)

diff --git a/c/include/proton/connection_driver.h b/c/include/proton/connection_driver.h
index 06b80ee..aa703b5 100644
--- a/c/include/proton/connection_driver.h
+++ b/c/include/proton/connection_driver.h
@@ -91,7 +91,6 @@ typedef struct pn_connection_driver_t {
   pn_connection_t *connection;
   pn_transport_t *transport;
   pn_collector_t *collector;
-  pn_event_batch_t batch;
 } pn_connection_driver_t;
 
 /**
@@ -234,12 +233,6 @@ PN_EXTERN void pn_connection_driver_errorf(pn_connection_driver_t *d, const char
 PN_EXTERN void pn_connection_driver_verrorf(pn_connection_driver_t *d, const char *name, const char *fmt, va_list);
 
 /**
- * If batch is part of a connection_driver, return the connection_driver address,
- * else return NULL
- */
-PN_EXTERN pn_connection_driver_t* pn_event_batch_connection_driver(pn_event_batch_t *batch);
-
-/**
  * The write side of the transport is closed, it will no longer produce bytes to write to
  * external IO. Synonym for PN_TRANSPORT_HEAD_CLOSED
  */
diff --git a/c/include/proton/event.h b/c/include/proton/event.h
index 8d62d6b..8e5fba2 100644
--- a/c/include/proton/event.h
+++ b/c/include/proton/event.h
@@ -539,38 +539,6 @@ PN_EXTERN pn_record_t *pn_event_attachments(pn_event_t *event);
  */
 PN_EXTERN struct pn_condition_t *pn_event_condition(pn_event_t *event);
 
-/**
- * **Unsettled API** - A batch of events that must be handled in sequence.
- * Call pn_event_batch_next() in a loop until it returns NULL to extract
- * the events.
- */
-typedef struct pn_event_batch_t pn_event_batch_t;
-
-/* NOTE: there is deliberately no peek(), more() or other look-ahead on an event
- * batch. We want to know exactly which events have been handled, next() only
- * allows the user to get each event exactly once, in order.
- */
-
-/**
- * **Unsettled API** - Remove the next event from the batch and return
- *  it. NULL means the batch is empty. The returned event pointer is
- *  valid until pn_event_batch_next() is called again on the same
- *  batch.
- */
-PN_EXTERN pn_event_t *pn_event_batch_next(pn_event_batch_t *batch);
-
-/**
- * @cond INTERNAL
- *
- * pn_event_batch_next() can be re-implemented for different behaviors in different contexts.
- */
-struct pn_event_batch_t {
-  pn_event_t *(*next_event)(pn_event_batch_t *batch);
-};
-/**
- * @endcond
- */
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/c/include/proton/proactor.h b/c/include/proton/proactor.h
index 88544bc..b0303c9 100644
--- a/c/include/proton/proactor.h
+++ b/c/include/proton/proactor.h
@@ -206,6 +206,18 @@ PNP_EXTERN pn_event_batch_t *pn_proactor_wait(pn_proactor_t *proactor);
 PNP_EXTERN pn_event_batch_t *pn_proactor_get(pn_proactor_t *proactor);
 
 /**
+ * Remove the next event from the batch and return
+ * it. NULL means the batch is empty. The returned event pointer is
+ * valid until pn_event_batch_next() is called again on the same
+ * batch.
+ *
+ * @note there is deliberately no peek(), more() or other look-ahead on an event
+ * batch. We want to know exactly which events have been handled, next() only
+ * allows the user to get each event exactly once, in order.
+ */
+PNP_EXTERN pn_event_t *pn_event_batch_next(pn_event_batch_t *batch);
+
+/**
  * Call when finished handling a batch of events.
  *
  * Must be called exactly once to match each call to pn_proactor_wait().
diff --git a/c/include/proton/types.h b/c/include/proton/types.h
index 227c98d..edcca98 100644
--- a/c/include/proton/types.h
+++ b/c/include/proton/types.h
@@ -438,6 +438,19 @@ typedef struct pn_transport_t pn_transport_t;
 typedef struct pn_proactor_t pn_proactor_t;
 
 /**
+ * A batch of events that must be handled in sequence.
+ *
+ * A pn_event_batch_t encapsulates potentially multiple events that relate
+ * to an individual proactor related source that must be handled in sequence.
+ *
+ * Call pn_event_batch_next() in a loop until it returns NULL to extract
+ * the batch's events.
+ *
+ * @ingroup proactor
+ */
+typedef struct pn_event_batch_t pn_event_batch_t;
+
+/**
  * @cond INTERNAL
  *
  * An event handler
diff --git a/c/src/core/connection_driver.c b/c/src/core/connection_driver.c
index 935a2b0..57fe64d 100644
--- a/c/src/core/connection_driver.c
+++ b/c/src/core/connection_driver.c
@@ -25,14 +25,7 @@
 #include <proton/transport.h>
 #include <string.h>
 
-struct driver_batch {
-  pn_event_batch_t batch;
-  pn_collector_t *collector;
-};
-
-static pn_event_t *batch_next(pn_event_batch_t *batch) {
-  pn_connection_driver_t *d =
-    (pn_connection_driver_t*)((char*)batch - offsetof(pn_connection_driver_t, batch));
+static pn_event_t *batch_next(pn_connection_driver_t *d) {
   if (!d->collector) return NULL;
   pn_event_t *handled = pn_collector_prev(d->collector);
   if (handled) {
@@ -59,7 +52,6 @@ static pn_event_t *batch_next(pn_event_batch_t *batch) {
 
 int pn_connection_driver_init(pn_connection_driver_t* d, pn_connection_t *c, pn_transport_t *t) {
   memset(d, 0, sizeof(*d));
-  d->batch.next_event = &batch_next;
   d->connection = c ? c : pn_connection();
   d->transport = t ? t : pn_transport();
   d->collector = pn_collector();
@@ -142,7 +134,7 @@ void pn_connection_driver_close(pn_connection_driver_t *d) {
 }
 
 pn_event_t* pn_connection_driver_next_event(pn_connection_driver_t *d) {
-  return pn_event_batch_next(&d->batch);
+  return batch_next(d);
 }
 
 bool pn_connection_driver_has_event(pn_connection_driver_t *d) {
@@ -183,10 +175,4 @@ void pn_connection_driver_vlogf(pn_connection_driver_t *d, const char *fmt, va_l
   pni_logger_vlogf(&d->transport->logger, PN_SUBSYSTEM_IO, PN_LEVEL_TRACE, fmt, ap);
 }
 
-pn_connection_driver_t* pn_event_batch_connection_driver(pn_event_batch_t *batch) {
-  return (batch->next_event == batch_next) ?
-    (pn_connection_driver_t*)((char*)batch - offsetof(pn_connection_driver_t, batch)) :
-    NULL;
-}
-
 pn_connection_driver_t** pn_connection_driver_ptr(pn_connection_t *c) { return &c->driver; }
diff --git a/c/src/core/event.c b/c/src/core/event.c
index c24131d..5a20d87 100644
--- a/c/src/core/event.c
+++ b/c/src/core/event.c
@@ -404,7 +404,3 @@ const char *pn_event_type_name(pn_event_type_t type)
   }
   return NULL;
 }
-
-pn_event_t *pn_event_batch_next(pn_event_batch_t *batch) {
-  return batch->next_event(batch);
-}
diff --git a/c/src/proactor/libuv.c b/c/src/proactor/libuv.c
index 2eb6e1c..fb27cd7 100644
--- a/c/src/proactor/libuv.c
+++ b/c/src/proactor/libuv.c
@@ -160,6 +160,7 @@ typedef struct pconnection_t {
 
   /* Only used by owner thread */
   pn_connection_driver_t driver;
+  pn_event_batch_t batch;
 
   /* Only used by leader */
   uv_tcp_t tcp;
@@ -324,12 +325,15 @@ static void set_pconnection(pn_connection_t* c, pconnection_t *pc) {
   uv_mutex_unlock(&driver_ptr_mutex);
 }
 
+static pn_event_t *pconnection_batch_next(pn_event_batch_t *batch);
+
 static pconnection_t *pconnection(pn_proactor_t *p, pn_connection_t *c, pn_transport_t *t, bool server) {
   pconnection_t *pc = (pconnection_t*)calloc(1, sizeof(*pc));
   if (!pc || pn_connection_driver_init(&pc->driver, c, t) != 0) {
     return NULL;
   }
   work_init(&pc->work, p,  T_CONNECTION);
+  pc->batch.next_event = pconnection_batch_next;
   pc->next = pconnection_unqueued;
   pc->write.data = &pc->work;
   uv_mutex_init(&pc->lock);
@@ -365,8 +369,8 @@ static inline pn_listener_t *batch_listener(pn_event_batch_t *batch) {
 }
 
 static inline pconnection_t *batch_pconnection(pn_event_batch_t *batch) {
-  pn_connection_driver_t *d = pn_event_batch_connection_driver(batch);
-  return d ? (pconnection_t*)((char*)d - offsetof(pconnection_t, driver)) : NULL;
+  return (batch->next_event == pconnection_batch_next) ?
+    (pconnection_t*)((char*)batch - offsetof(pconnection_t, batch)) : NULL;
 }
 
 static inline work_t *batch_work(pn_event_batch_t *batch) {
@@ -840,6 +844,11 @@ static pn_event_t *proactor_batch_next(pn_event_batch_t *batch) {
   return log_event(p, pn_collector_next(p->collector));
 }
 
+static pn_event_t *pconnection_batch_next(pn_event_batch_t *batch) {
+  pconnection_t *pc = batch_pconnection(batch);
+  return pn_connection_driver_next_event(&pc->driver);
+}
+
 /* Return the next event batch or NULL if no events are available */
 static pn_event_batch_t *get_batch_lh(pn_proactor_t *p) {
   if (!p->batch_working) {       /* Can generate proactor events */
@@ -861,7 +870,7 @@ static pn_event_batch_t *get_batch_lh(pn_proactor_t *p) {
     assert(w->working);
     switch (w->type) {
      case T_CONNECTION:
-      return &((pconnection_t*)w)->driver.batch;
+      return &((pconnection_t*)w)->batch;
      case T_LISTENER:
       return &((pn_listener_t*)w)->batch;
      default:
diff --git a/c/src/proactor/proactor-internal.c b/c/src/proactor/proactor-internal.c
index 8c53785..bc597e8 100644
--- a/c/src/proactor/proactor-internal.c
+++ b/c/src/proactor/proactor-internal.c
@@ -87,6 +87,10 @@ void pni_proactor_set_cond(
   }
 }
 
+pn_event_t *pn_event_batch_next(pn_event_batch_t *batch) {
+  return batch->next_event(batch);
+}
+
 // Backwards compatibility signatures.
 
 void pn_proactor_connect(pn_proactor_t *p, pn_connection_t *c, const char *addr) {
diff --git a/c/src/proactor/proactor-internal.h b/c/src/proactor/proactor-internal.h
index cc5f2cb..88e61c0 100644
--- a/c/src/proactor/proactor-internal.h
+++ b/c/src/proactor/proactor-internal.h
@@ -21,6 +21,7 @@
  */
 
 #include <proton/condition.h>
+#include <proton/event.h>
 #include <proton/import_export.h>
 #include <proton/type_compat.h>
 
@@ -52,6 +53,13 @@ extern const char *PNI_IO_CONDITION;
 void pni_proactor_set_cond(
   pn_condition_t *cond, const char *what, const char *host, const char *port, const char *msg);
 
+/**
+ * pn_event_batch_next() can be re-implemented for different behaviors in different contexts.
+ */
+struct pn_event_batch_t {
+  pn_event_t *(*next_event)(pn_event_batch_t *batch);
+};
+
 #ifdef __cplusplus
 }
 #endif


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