connection_engine::connection_engine(class handler &h, const connection_options& opts) { connection_ = proton::connection(take_ownership(pn_connection()).get()); pn_ptr<pn_transport_t> transport = take_ownership(pn_transport()); pn_ptr<pn_collector_t> collector = take_ownership(pn_collector()); if (!connection_ || !transport || !collector) throw proton::error("engine create"); int err = pn_transport_bind(transport.get(), connection_.pn_object()); if (err) throw error(msg() << "transport bind:" << pn_code(err)); pn_connection_collect(connection_.pn_object(), collector.get()); ctx_ = &connection_engine_context::get(connection_); // Creates context ctx_->engine_handler = &h; ctx_->transport = transport.release(); ctx_->collector = collector.release(); opts.apply(connection_); // Provide defaults for connection_id and link_prefix if not set. std::string cid = connection_.container_id(); if (cid.empty()) { cid = make_id(); pn_connection_set_container(connection_.pn_object(), cid.c_str()); } id_generator &link_gen = connection_context::get(connection_).link_gen; if (link_gen.prefix().empty()) { link_gen.prefix(make_id()+"/"); } }
void pni_handle_open(pn_reactor_t *reactor, pn_event_t *event) { assert(reactor); assert(event); pn_connection_t *conn = pn_event_connection(event); if (!(pn_connection_state(conn) & PN_REMOTE_UNINIT)) { return; } pn_transport_t *transport = pn_transport(); pn_transport_bind(transport, conn); pn_decref(transport); }
connection_engine::connection_engine(class container& cont, link_namer& namer, event_loop* loop) : handler_(0), connection_(make_wrapper(internal::take_ownership(pn_connection()).get())), transport_(make_wrapper(internal::take_ownership(pn_transport()).get())), collector_(internal::take_ownership(pn_collector()).get()), container_(cont) { if (!connection_ || !transport_ || !collector_) throw proton::error("connection_engine create failed"); pn_transport_bind(unwrap(transport_), unwrap(connection_)); pn_connection_collect(unwrap(connection_), collector_.get()); connection_context& ctx = connection_context::get(connection_); ctx.container = &container_; ctx.link_gen = &namer; ctx.event_loop.reset(loop); }
void connector::connect() { pn_transport_t *pnt = pn_transport(); transport t(make_wrapper(pnt)); if (!address_.user().empty()) connection_.user(address_.user()); if (!address_.password().empty()) connection_.password(address_.password()); pn_transport_bind(pnt, unwrap(connection_)); pn_decref(pnt); // Apply options to the new transport. options_.apply(connection_); // if virtual-host not set, use host from address as default if (!options_.is_virtual_host_set()) pn_connection_set_hostname(unwrap(connection_), address_.host().c_str()); transport_configured_ = true; }