qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject qpid-proton git commit: PROTON-1866: provide method to determine whether expiry policy was set explicitly or not
Date Mon, 25 Jun 2018 17:48:48 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master b1b8322b2 -> ccb9e5a38


PROTON-1866: provide method to determine whether expiry policy was set explicitly or not


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

Branch: refs/heads/master
Commit: ccb9e5a388022e529502dcc547b7862b2185d6bc
Parents: b1b8322
Author: Gordon Sim <gsim@redhat.com>
Authored: Mon Jun 25 17:52:19 2018 +0100
Committer: Gordon Sim <gsim@redhat.com>
Committed: Mon Jun 25 17:52:40 2018 +0100

----------------------------------------------------------------------
 c/include/proton/terminus.h  | 11 ++++++++++
 c/src/core/engine-internal.h |  1 +
 c/src/core/engine.c          |  8 ++++++++
 c/src/core/transport.c       | 43 +++++++++++++++++++--------------------
 4 files changed, 41 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccb9e5a3/c/include/proton/terminus.h
----------------------------------------------------------------------
diff --git a/c/include/proton/terminus.h b/c/include/proton/terminus.h
index b2344c0..096ab17 100644
--- a/c/include/proton/terminus.h
+++ b/c/include/proton/terminus.h
@@ -191,6 +191,15 @@ PN_EXTERN int pn_terminus_set_durability(pn_terminus_t *terminus,
 PN_EXTERN pn_expiry_policy_t pn_terminus_get_expiry_policy(pn_terminus_t *terminus);
 
 /**
+ * Return true if the terminus has an explicit expiry policy set,
+ * false if it does not.
+ *
+ * @param[in] terminus a terminus object
+ * @return whether the terminus has an explicit expiry-policy
+ */
+PN_EXTERN bool pn_terminus_has_expiry_policy(const pn_terminus_t *terminus);
+
+/**
  * Set the expiry policy of a terminus object.
  *
  * @param[in] terminus a terminus object
@@ -199,6 +208,8 @@ PN_EXTERN pn_expiry_policy_t pn_terminus_get_expiry_policy(pn_terminus_t
*termin
  */
 PN_EXTERN int pn_terminus_set_expiry_policy(pn_terminus_t *terminus, pn_expiry_policy_t policy);
 
+
+
 /**
  * Get the timeout of a terminus object.
  *

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccb9e5a3/c/src/core/engine-internal.h
----------------------------------------------------------------------
diff --git a/c/src/core/engine-internal.h b/c/src/core/engine-internal.h
index b1c6123..66a892d 100644
--- a/c/src/core/engine-internal.h
+++ b/c/src/core/engine-internal.h
@@ -274,6 +274,7 @@ struct pn_terminus_t {
   pn_data_t *filter;
   pn_durability_t durability;
   pn_expiry_policy_t expiry_policy;
+  bool has_expiry_policy;
   pn_seconds_t timeout;
   pn_terminus_type_t type;
   pn_distribution_mode_t distribution_mode;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccb9e5a3/c/src/core/engine.c
----------------------------------------------------------------------
diff --git a/c/src/core/engine.c b/c/src/core/engine.c
index 070c751..e70117e 100644
--- a/c/src/core/engine.c
+++ b/c/src/core/engine.c
@@ -1085,6 +1085,7 @@ static void pni_terminus_init(pn_terminus_t *terminus, pn_terminus_type_t
type)
   terminus->type = type;
   terminus->address = pn_string(NULL);
   terminus->durability = PN_NONDURABLE;
+  terminus->has_expiry_policy = false;
   terminus->expiry_policy = PN_EXPIRE_WITH_SESSION;
   terminus->timeout = 0;
   terminus->dynamic = false;
@@ -1267,10 +1268,16 @@ pn_expiry_policy_t pn_terminus_get_expiry_policy(pn_terminus_t *terminus)
   return terminus ? terminus->expiry_policy : (pn_expiry_policy_t) 0;
 }
 
+bool pn_terminus_has_expiry_policy(const pn_terminus_t *terminus)
+{
+    return terminus && terminus->has_expiry_policy;
+}
+
 int pn_terminus_set_expiry_policy(pn_terminus_t *terminus, pn_expiry_policy_t expiry_policy)
 {
   if (!terminus) return PN_ARG_ERR;
   terminus->expiry_policy = expiry_policy;
+  terminus->has_expiry_policy = true;
   return 0;
 }
 
@@ -1340,6 +1347,7 @@ int pn_terminus_copy(pn_terminus_t *terminus, pn_terminus_t *src)
   int err = pn_terminus_set_address(terminus, pn_terminus_get_address(src));
   if (err) return err;
   terminus->durability = src->durability;
+  terminus->has_expiry_policy = src->has_expiry_policy;
   terminus->expiry_policy = src->expiry_policy;
   terminus->timeout = src->timeout;
   terminus->dynamic = src->dynamic;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccb9e5a3/c/src/core/transport.c
----------------------------------------------------------------------
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index bfa66c1..dde4b37 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -1274,21 +1274,18 @@ static pn_link_t *pni_find_link(pn_session_t *ssn, pn_bytes_t name,
bool is_send
   return NULL;
 }
 
-static pn_expiry_policy_t symbol2policy(pn_bytes_t symbol)
+static void set_expiry_policy_from_symbol(pn_terminus_t* terminus, pn_bytes_t symbol)
 {
-  if (!symbol.start)
-    return PN_EXPIRE_WITH_SESSION;
-
-  if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(link-detach)))
-    return PN_EXPIRE_WITH_LINK;
-  if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(session-end)))
-    return PN_EXPIRE_WITH_SESSION;
-  if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(connection-close)))
-    return PN_EXPIRE_WITH_CONNECTION;
-  if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(never)))
-    return PN_EXPIRE_NEVER;
-
-  return PN_EXPIRE_WITH_SESSION;
+  if (symbol.start) {
+    if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(link-detach)))
+      pn_terminus_set_expiry_policy(terminus, PN_EXPIRE_WITH_LINK);
+    if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(session-end)))
+      pn_terminus_set_expiry_policy(terminus, PN_EXPIRE_WITH_SESSION);
+    if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(connection-close)))
+      pn_terminus_set_expiry_policy(terminus, PN_EXPIRE_WITH_CONNECTION);
+    if (pn_bytes_equal(symbol, PN_BYTES_LITERAL(never)))
+      pn_terminus_set_expiry_policy(terminus, PN_EXPIRE_NEVER);
+  }
 }
 
 static pn_distribution_mode_t symbol2dist_mode(const pn_bytes_t symbol)
@@ -1383,7 +1380,7 @@ int pn_do_attach(pn_transport_t *transport, uint8_t frame_type, uint16_t
channel
     pn_terminus_set_type(rsrc, PN_SOURCE);
     pn_terminus_set_address_bytes(rsrc, source);
     pn_terminus_set_durability(rsrc, src_dr);
-    pn_terminus_set_expiry_policy(rsrc, symbol2policy(src_exp));
+    set_expiry_policy_from_symbol(rsrc, src_exp);
     pn_terminus_set_timeout(rsrc, src_timeout);
     pn_terminus_set_dynamic(rsrc, src_dynamic);
     pn_terminus_set_distribution_mode(rsrc, symbol2dist_mode(dist_mode));
@@ -1395,7 +1392,7 @@ int pn_do_attach(pn_transport_t *transport, uint8_t frame_type, uint16_t
channel
     pn_terminus_set_type(rtgt, PN_TARGET);
     pn_terminus_set_address_bytes(rtgt, target);
     pn_terminus_set_durability(rtgt, tgt_dr);
-    pn_terminus_set_expiry_policy(rtgt, symbol2policy(tgt_exp));
+    set_expiry_policy_from_symbol(rtgt, tgt_exp);
     pn_terminus_set_timeout(rtgt, tgt_timeout);
     pn_terminus_set_dynamic(rtgt, tgt_dynamic);
   } else {
@@ -1958,14 +1955,16 @@ static int pni_process_ssn_setup(pn_transport_t *transport, pn_endpoint_t
*endpo
   return 0;
 }
 
-static const char *expiry_symbol(pn_expiry_policy_t policy)
+static const char *expiry_symbol(pn_terminus_t* terminus)
 {
-  switch (policy)
+  if (!terminus->has_expiry_policy) return NULL;
+
+  switch (terminus->expiry_policy)
   {
   case PN_EXPIRE_WITH_LINK:
     return "link-detach";
   case PN_EXPIRE_WITH_SESSION:
-    return NULL;
+    return "session-end";
   case PN_EXPIRE_WITH_CONNECTION:
     return "connection-close";
   case PN_EXPIRE_NEVER:
@@ -2011,7 +2010,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t
*endp
                                 (bool) link->source.type, SOURCE,
                                 pn_string_get(link->source.address),
                                 link->source.durability,
-                                expiry_symbol(link->source.expiry_policy),
+                                expiry_symbol(&link->source),
                                 link->source.timeout,
                                 link->source.dynamic,
                                 link->source.properties,
@@ -2033,7 +2032,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t
*endp
                                 (bool) link->source.type, SOURCE,
                                 pn_string_get(link->source.address),
                                 link->source.durability,
-                                expiry_symbol(link->source.expiry_policy),
+                                expiry_symbol(&link->source),
                                 link->source.timeout,
                                 link->source.dynamic,
                                 link->source.properties,
@@ -2044,7 +2043,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t
*endp
                                 (bool) link->target.type, TARGET,
                                 pn_string_get(link->target.address),
                                 link->target.durability,
-                                expiry_symbol(link->target.expiry_policy),
+                                expiry_symbol(&link->target),
                                 link->target.timeout,
                                 link->target.dynamic,
                                 link->target.properties,


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


Mime
View raw message