PROTON-1452: Test for closed transport without side effects "closed" tests based on pn_transport_pending/available have side effects: may generate events or modify read/write buffer pointers, which makes using those tests very sensitive to ordering.
New pn_transport_(head|tail)_closed have no side effects. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/893cb001 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/893cb001 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/893cb001 Branch: refs/heads/master Commit: 893cb00161d29e2e29c7e7304177f3d92418f405 Parents: 7a68a2c Author: Alan Conway <acon...@redhat.com> Authored: Wed Mar 29 16:42:31 2017 -0400 Committer: Alan Conway <acon...@redhat.com> Committed: Wed Mar 29 17:58:56 2017 -0400 ---------------------------------------------------------------------- proton-c/include/proton/transport.h | 19 +++++++++++-------- proton-c/src/core/connection_driver.c | 4 ++-- proton-c/src/core/transport.c | 12 ++++++------ 3 files changed, 19 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/893cb001/proton-c/include/proton/transport.h ---------------------------------------------------------------------- diff --git a/proton-c/include/proton/transport.h b/proton-c/include/proton/transport.h index 09fbb03..89b6fad 100644 --- a/proton-c/include/proton/transport.h +++ b/proton-c/include/proton/transport.h @@ -610,14 +610,17 @@ PN_EXTERN int pn_transport_close_head(pn_transport_t *transport); PN_EXTERN bool pn_transport_quiesced(pn_transport_t *transport); /** - * Check if a transport is closed. - * - * A transport is defined to be closed when both the tail and the head - * are closed. In other words, when both ::pn_transport_capacity() < 0 - * and ::pn_transport_pending() < 0. - * - * @param[in] transport a transport object - * @return true if the transport is closed, false otherwise + * True if pn_transport_close_head() has been called. + */ +PN_EXTERN bool pn_transport_head_closed(pn_transport_t *transport); + +/** + * True if pn_transport_close_tail() has been called. + */ +PN_EXTERN bool pn_transport_tail_closed(pn_transport_t *transport); + +/** + * Equivalent to pn_transport_head_closed(transport) && pn_transport_tail_closed(transport) */ PN_EXTERN bool pn_transport_closed(pn_transport_t *transport); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/893cb001/proton-c/src/core/connection_driver.c ---------------------------------------------------------------------- diff --git a/proton-c/src/core/connection_driver.c b/proton-c/src/core/connection_driver.c index f5fddae..40af749 100644 --- a/proton-c/src/core/connection_driver.c +++ b/proton-c/src/core/connection_driver.c @@ -90,7 +90,7 @@ void pn_connection_driver_read_done(pn_connection_driver_t *d, size_t n) { } bool pn_connection_driver_read_closed(pn_connection_driver_t *d) { - return pn_transport_capacity(d->transport) < 0; + return pn_transport_tail_closed(d->transport); } void pn_connection_driver_read_close(pn_connection_driver_t *d) { @@ -111,7 +111,7 @@ void pn_connection_driver_write_done(pn_connection_driver_t *d, size_t n) { } bool pn_connection_driver_write_closed(pn_connection_driver_t *d) { - return pn_transport_pending(d->transport) < 0; + return pn_transport_head_closed(d->transport); } void pn_connection_driver_write_close(pn_connection_driver_t *d) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/893cb001/proton-c/src/core/transport.c ---------------------------------------------------------------------- diff --git a/proton-c/src/core/transport.c b/proton-c/src/core/transport.c index 444145a..5065663 100644 --- a/proton-c/src/core/transport.c +++ b/proton-c/src/core/transport.c @@ -3009,12 +3009,12 @@ bool pn_transport_quiesced(pn_transport_t *transport) return true; } -bool pn_transport_closed(pn_transport_t *transport) -{ - assert(transport); - ssize_t capacity = pn_transport_capacity(transport); - ssize_t pending = pn_transport_pending(transport); - return capacity < 0 && pending < 0; +bool pn_transport_head_closed(pn_transport_t *transport) { return transport->head_closed; } + +bool pn_transport_tail_closed(pn_transport_t *transport) { return transport->tail_closed; } + +bool pn_transport_closed(pn_transport_t *transport) { + return transport->head_closed && transport->tail_closed; } pn_connection_t *pn_transport_connection(pn_transport_t *transport) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org