Repository: qpid-proton Updated Branches: refs/heads/master 3f4dc74a4 -> c9158ed3a
PROTON-1076: C++ Binding - per acceptor connection options (acceptor context) Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c9158ed3 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c9158ed3 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c9158ed3 Branch: refs/heads/master Commit: c9158ed3ac6dd68590bddd061a7e0180d74abc90 Parents: 3f4dc74 Author: Clifford Jansen <cliffjan...@apache.org> Authored: Sat Dec 12 08:31:59 2015 -0800 Committer: Clifford Jansen <cliffjan...@apache.org> Committed: Sat Dec 12 08:31:59 2015 -0800 ---------------------------------------------------------------------- .../bindings/cpp/include/proton/acceptor.hpp | 10 +++++++--- .../bindings/cpp/include/proton/container.hpp | 2 +- proton-c/bindings/cpp/include/proton/ssl.hpp | 4 ++-- proton-c/bindings/cpp/src/acceptor.cpp | 7 +++++++ proton-c/bindings/cpp/src/connection_options.cpp | 5 +---- proton-c/bindings/cpp/src/container.cpp | 4 ---- proton-c/bindings/cpp/src/container_impl.cpp | 19 +++---------------- proton-c/bindings/cpp/src/container_impl.hpp | 2 +- proton-c/bindings/cpp/src/contexts.cpp | 15 +++++++++++++++ proton-c/bindings/cpp/src/contexts.hpp | 8 ++++++++ 10 files changed, 45 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/include/proton/acceptor.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/acceptor.hpp b/proton-c/bindings/cpp/include/proton/acceptor.hpp index c5726aa..4edcc11 100644 --- a/proton-c/bindings/cpp/include/proton/acceptor.hpp +++ b/proton-c/bindings/cpp/include/proton/acceptor.hpp @@ -38,9 +38,13 @@ class acceptor : public object<pn_acceptor_t> /** close the acceptor */ PN_CPP_EXTERN void close(); -#ifndef PROTON_1057_FIXED - friend class container_impl; -#endif + + /** Return the current set of connection options applied to inbound connectons by the acceptor. + * + * Note that changes made to the connection options only affect connections accepted after this + * call returns. + */ + PN_CPP_EXTERN class connection_options &connection_options(); }; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/include/proton/container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp index 2cebcd4..fbdafb9 100644 --- a/proton-c/bindings/cpp/include/proton/container.hpp +++ b/proton-c/bindings/cpp/include/proton/container.hpp @@ -62,7 +62,7 @@ class container : public event_loop { /** Locally open a connection @see connection::open */ PN_CPP_EXTERN connection connect(const proton::url&, const connection_options &opts = connection_options()); - /** Open a connection to url and create a receiver with source=url.path() */ + /** Listen on url host and port for incoming connections. */ PN_CPP_EXTERN acceptor listen(const proton::url&, const connection_options &opts = connection_options()); /** Run the event loop, return when all connections and acceptors are closed. */ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/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 bb78ae3..609e7e2 100644 --- a/proton-c/bindings/cpp/include/proton/ssl.hpp +++ b/proton-c/bindings/cpp/include/proton/ssl.hpp @@ -104,9 +104,9 @@ class server_domain : private ssl_domain { PN_CPP_EXTERN ~server_domain(); private: - // Bring pn_domain into scope and allow container_impl to use it + // Bring pn_domain into scope and allow connection_options to use it using ssl_domain::pn_domain; - friend class container_impl; + friend class connection_options; }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/acceptor.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/acceptor.cpp b/proton-c/bindings/cpp/src/acceptor.cpp index 279f776..8f4c722 100644 --- a/proton-c/bindings/cpp/src/acceptor.cpp +++ b/proton-c/bindings/cpp/src/acceptor.cpp @@ -21,10 +21,17 @@ #include "proton/acceptor.hpp" #include "proton/error.hpp" +#include "proton/connection_options.hpp" #include "msg.hpp" +#include "contexts.hpp" namespace proton { void acceptor::close() { pn_acceptor_close(pn_object()); } +class connection_options& acceptor::connection_options() { + listener_context& lc(listener_context::get(pn_object())); + return lc.connection_options; +} + } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/connection_options.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/connection_options.cpp b/proton-c/bindings/cpp/src/connection_options.cpp index 6b72c9c..3a3e0e1 100644 --- a/proton-c/bindings/cpp/src/connection_options.cpp +++ b/proton-c/bindings/cpp/src/connection_options.cpp @@ -73,7 +73,6 @@ class connection_options::impl { { // SSL if (outbound && outbound->address().scheme() == url::AMQPS) { - // Configure outbound ssl options. pni_acceptor_readable handles the inbound case. const char* id = resume_id.value.empty() ? NULL : resume_id.value.c_str(); pn_ssl_t *ssl = pn_ssl(pnt); if (pn_ssl_init(ssl, client_domain.value.pn_domain(), id)) @@ -81,16 +80,14 @@ class connection_options::impl { if (peer_hostname.set && !peer_hostname.value.empty()) if (pn_ssl_set_peer_hostname(ssl, peer_hostname.value.c_str())) throw error(MSG("error in SSL/TLS peer hostname \"") << peer_hostname.value << '"'); -#ifdef PROTON_1054_FIXED } else if (!outbound) { - pn_acceptor_t *pnp = pn_connection_acceptor(pn_cast(&c)); + pn_acceptor_t *pnp = pn_connection_acceptor(pnc); listener_context &lc(listener_context::get(pnp)); if (lc.ssl) { pn_ssl_t *ssl = pn_ssl(pnt); if (pn_ssl_init(ssl, server_domain.value.pn_domain(), NULL)) throw error(MSG("server SSL/TLS initialization error")); } -#endif } // SASL http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/container.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/container.cpp b/proton-c/bindings/cpp/src/container.cpp index 34bd2a0..1924cc0 100644 --- a/proton-c/bindings/cpp/src/container.cpp +++ b/proton-c/bindings/cpp/src/container.cpp @@ -67,11 +67,7 @@ receiver container::open_receiver(const proton::url &url) { } acceptor container::listen(const proton::url &url, const connection_options &opts) { -#ifdef PN_COMING_SOON return impl_->listen(url, opts); -#else - return impl_->listen(url); -#endif } task container::schedule(int delay, handler *h) { return impl_->schedule(delay, h); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/container_impl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/container_impl.cpp b/proton-c/bindings/cpp/src/container_impl.cpp index 648aa56..e3c7c2c 100644 --- a/proton-c/bindings/cpp/src/container_impl.cpp +++ b/proton-c/bindings/cpp/src/container_impl.cpp @@ -185,11 +185,9 @@ receiver container_impl::open_receiver(const proton::url &url) { return rcv; } -acceptor container_impl::listen(const proton::url& url) { +acceptor container_impl::listen(const proton::url& url, const connection_options &user_opts) { connection_options opts = server_connection_options(); // Defaults -#ifdef PN_COMING_SOON opts.override(user_opts); -#endif handler *h = opts.handler(); pn_ptr<pn_handler_t> chandler = h ? cpp_handler(h) : pn_ptr<pn_handler_t>(); pn_acceptor_t *acptr = pn_reactor_acceptor(reactor_.pn_object(), url.host().c_str(), url.port().c_str(), chandler.get()); @@ -197,16 +195,11 @@ acceptor container_impl::listen(const proton::url& url) { throw error(MSG("accept fail: " << pn_error_text(pn_io_error(reactor_.pn_io()))) << "(" << url << ")"); -#ifdef PROTON_1054_FIXED // Do not use pn_acceptor_set_ssl_domain(). Manage the incoming connections ourselves for // more flexibility (i.e. ability to change the server cert for a long running listener). listener_context& lc(listener_context::get(acptr)); lc.connection_options = opts; lc.ssl = url.scheme() == url::AMQPS; -#else - if (url.scheme() == url::AMQPS) - pn_acceptor_set_ssl_domain(acptr, server_connection_options_.server_domain().pn_domain()); -#endif return acceptor(acptr); } @@ -233,15 +226,9 @@ void container_impl::server_connection_options(const connection_options &opts) { } void container_impl::configure_server_connection(connection &c) { -#ifdef PN_1054_FIXED - pn_acceptor_t *pnp = pn_connection_acceptor(pn_cast(&c)); + pn_acceptor_t *pnp = pn_connection_acceptor(connection_options::pn_connection(c)); listener_context &lc(listener_context::get(pnp)); - class connection_options &opts(lc.connection_options); -#else - // Can't distinguish between multiple listeners yet. See PROTON-1054 - class connection_options &opts(server_connection_options_); -#endif - opts.apply(c); + lc.connection_options.apply(c); } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/container_impl.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/container_impl.hpp b/proton-c/bindings/cpp/src/container_impl.hpp index 4a89ab3..31ec0cf 100644 --- a/proton-c/bindings/cpp/src/container_impl.hpp +++ b/proton-c/bindings/cpp/src/container_impl.hpp @@ -52,7 +52,7 @@ class container_impl PN_CPP_EXTERN sender open_sender(const url&); PN_CPP_EXTERN receiver open_receiver(connection &connection, const std::string &addr, bool dynamic, handler *h); PN_CPP_EXTERN receiver open_receiver(const url&); - PN_CPP_EXTERN class acceptor listen(const url&); + PN_CPP_EXTERN class acceptor listen(const url&, const connection_options &); PN_CPP_EXTERN duration timeout(); PN_CPP_EXTERN void timeout(duration timeout); void client_connection_options(const connection_options &); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/contexts.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/contexts.cpp b/proton-c/bindings/cpp/src/contexts.cpp index 0ea4262..08187a2 100644 --- a/proton-c/bindings/cpp/src/contexts.cpp +++ b/proton-c/bindings/cpp/src/contexts.cpp @@ -48,6 +48,7 @@ pn_class_t cpp_context_class = PN_CLASS(cpp_context); // Handles PN_HANDLE(CONNECTION_CONTEXT) PN_HANDLE(CONTAINER_CONTEXT) +PN_HANDLE(LISTENER_CONTEXT) } context::~context() {} @@ -89,4 +90,18 @@ container &container_context::get(pn_reactor_t *pn_reactor) { return *ctx; } +listener_context& listener_context::get(pn_acceptor_t* a) { + // A Proton C pn_acceptor_t is really just a selectable + pn_selectable_t *sel = reinterpret_cast<pn_selectable_t*>(a); + + listener_context* ctx = + get_context<listener_context>(pn_selectable_attachments(sel), LISTENER_CONTEXT); + if (!ctx) { + ctx = context::create<listener_context>(); + set_context(pn_selectable_attachments(sel), LISTENER_CONTEXT, context::pn_class(), ctx); + pn_decref(ctx); + } + return *ctx; +} + } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c9158ed3/proton-c/bindings/cpp/src/contexts.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/contexts.hpp b/proton-c/bindings/cpp/src/contexts.hpp index c12d8bd..9bfd2d4 100644 --- a/proton-c/bindings/cpp/src/contexts.hpp +++ b/proton-c/bindings/cpp/src/contexts.hpp @@ -76,6 +76,14 @@ class container_context { static container& get(pn_reactor_t*); }; +class listener_context : public context { + public: + static listener_context& get(pn_acceptor_t* c); + listener_context() : ssl(false) {} + class connection_options connection_options; + bool ssl; +}; + } #endif /*!PROTON_CPP_CONTEXTS_H*/ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org