Repository: qpid-proton Updated Branches: refs/heads/master 35c9c5232 -> 8897f87af
PROTON-1119: more efficient tracking of ssl_domain objects in C++ Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/8897f87a Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/8897f87a Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/8897f87a Branch: refs/heads/master Commit: 8897f87affc3343046bac172a5dd32cb8a776992 Parents: 35c9c52 Author: Clifford Jansen <[email protected]> Authored: Mon Feb 1 09:24:31 2016 -0500 Committer: Clifford Jansen <[email protected]> Committed: Mon Feb 1 09:24:31 2016 -0500 ---------------------------------------------------------------------- proton-c/bindings/cpp/include/proton/ssl.hpp | 1 + proton-c/bindings/cpp/src/ssl_domain.cpp | 36 +++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8897f87a/proton-c/bindings/cpp/include/proton/ssl.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/ssl.hpp b/proton-c/bindings/cpp/include/proton/ssl.hpp index d2111c9..7cfdc69 100644 --- a/proton-c/bindings/cpp/include/proton/ssl.hpp +++ b/proton-c/bindings/cpp/include/proton/ssl.hpp @@ -126,6 +126,7 @@ class ssl_domain { private: ssl_domain_impl *impl_; + bool server_type_; }; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8897f87a/proton-c/bindings/cpp/src/ssl_domain.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ssl_domain.cpp b/proton-c/bindings/cpp/src/ssl_domain.cpp index 78332cd..a2e36d2 100644 --- a/proton-c/bindings/cpp/src/ssl_domain.cpp +++ b/proton-c/bindings/cpp/src/ssl_domain.cpp @@ -28,49 +28,49 @@ namespace proton { class ssl_domain_impl { public: - ssl_domain_impl(bool is_server) : refcount_(1), server_type_(is_server), pn_domain_(0) {} + ssl_domain_impl(bool is_server) : refcount_(1) { + pn_domain_ = pn_ssl_domain(is_server ? PN_SSL_MODE_SERVER : PN_SSL_MODE_CLIENT); + if (!pn_domain_) throw error(MSG("SSL/TLS unavailable")); + } void incref() { refcount_++; } void decref() { if (--refcount_ == 0) { - if (pn_domain_) pn_ssl_domain_free(pn_domain_); + pn_ssl_domain_free(pn_domain_); delete this; } } - pn_ssl_domain_t *pn_domain(); + pn_ssl_domain_t *pn_domain() { return pn_domain_; } private: int refcount_; - bool server_type_; pn_ssl_domain_t *pn_domain_; ssl_domain_impl(const ssl_domain_impl&); ssl_domain_impl& operator=(const ssl_domain_impl&); }; -pn_ssl_domain_t *ssl_domain_impl::pn_domain() { - if (pn_domain_) return pn_domain_; - // Lazily create in case never actually used or configured. - pn_domain_ = pn_ssl_domain(server_type_ ? PN_SSL_MODE_SERVER : PN_SSL_MODE_CLIENT); - if (!pn_domain_) throw error(MSG("SSL/TLS unavailable")); - return pn_domain_; -} - namespace internal { -ssl_domain::ssl_domain(bool is_server) : impl_(new ssl_domain_impl(is_server)) {} +ssl_domain::ssl_domain(bool is_server) : impl_(0), server_type_(is_server) {} ssl_domain::ssl_domain(const ssl_domain &x) { impl_ = x.impl_; - impl_->incref(); + if (impl_) impl_->incref(); } ssl_domain& internal::ssl_domain::operator=(const ssl_domain&x) { - impl_->decref(); + if (impl_) impl_->decref(); impl_ = x.impl_; - impl_->incref(); + if (impl_) impl_->incref(); return *this; } -ssl_domain::~ssl_domain() { impl_->decref(); } +ssl_domain::~ssl_domain() { if (impl_) impl_->decref(); } -pn_ssl_domain_t *ssl_domain::pn_domain() { return impl_->pn_domain(); } +pn_ssl_domain_t *ssl_domain::pn_domain() { + if (!impl_) + // Lazily create in case never actually used or configured. + // The pn_ssl_domain_t is a heavy object. + impl_ = new ssl_domain_impl(server_type_); + return impl_->pn_domain(); +} } // namespace internal --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
