PROTON-1255: Remove pn_connection_engine_start
Bind the connection automatically in pn_connection_engine_dispatch after the
user has processed the PN_CONNECTION_INIT event. This removes the need to
manually call start and allows user handlers to set security settings
in their handler on PN_CONNECTION_INIT, before the bind.
diff --git a/proton-c/bindings/cpp/src/io/connection_engine.cpp b/proton-c/bindings/cpp/src/io/connection_engine.cpp
index d3f2667..4712b3e 100644
--- a/proton-c/bindings/cpp/src/io/connection_engine.cpp
+++ b/proton-c/bindings/cpp/src/io/connection_engine.cpp
@@ -65,7 +65,6 @@
opts.apply_bound(c);
handler_ = opts.handler();
connection_context::get(connection()).collector = c_engine_.collector;
- pn_connection_engine_start(&c_engine_);
}
connection_engine::~connection_engine() {
diff --git a/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go b/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go
index a0b8888..5680010 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go
@@ -283,7 +283,6 @@
// disconnected. You can check for errors after exit with Engine.Error().
//
func (eng *Engine) Run() error {
- C.pn_connection_engine_start(&eng.engine)
// Channels for read and write buffers going in and out of the read/write goroutines.
// The channels are unbuffered: we want to exchange buffers in seuquence.
readsIn, writesIn := make(chan []byte), make(chan []byte)
diff --git a/proton-c/include/proton/connection_engine.h b/proton-c/include/proton/connection_engine.h
index b1476c7..d9df77b 100644
--- a/proton-c/include/proton/connection_engine.h
+++ b/proton-c/include/proton/connection_engine.h
@@ -87,18 +87,12 @@
/// Initialize a pn_connection_engine_t struct with a new connection and
/// transport.
///
-/// Configure connection properties and call connection_engine_start() before
-/// using the engine.
-///
/// Call pn_connection_engine_final to free resources when you are done.
///
///@return 0 on success, a proton error code on failure (@see error.h)
///
PN_EXTERN int pn_connection_engine_init(pn_connection_engine_t* engine);
-/// Start the engine, call after setting security and host properties.
-PN_EXTERN void pn_connection_engine_start(pn_connection_engine_t* engine);
-
/// Free resources used by the engine, set the connection and transport pointers
/// to NULL.
PN_EXTERN void pn_connection_engine_final(pn_connection_engine_t* engine);
diff --git a/proton-c/src/engine/connection_engine.c b/proton-c/src/engine/connection_engine.c
index adfb145..5d184a1 100644
--- a/proton-c/src/engine/connection_engine.c
+++ b/proton-c/src/engine/connection_engine.c
@@ -36,14 +36,6 @@
return PN_OK;
}
-void pn_connection_engine_start(pn_connection_engine_t* e) {
- /*
- Ignore bind errors. PN_STATE_ERR means we are already bound, any
- other error will be delivered as an event.
- */
- pn_transport_bind(e->transport, e->connection);
-}
-
void pn_connection_engine_final(pn_connection_engine_t* e) {
if (e->transport && e->connection) {
pn_transport_unbind(e->transport);
@@ -105,8 +97,11 @@
}
pn_event_t* pn_connection_engine_dispatch(pn_connection_engine_t* e) {
- if (e->event)
+ if (e->event) { /* Already returned */
+ if (pn_event_type(e->event) == PN_CONNECTION_INIT)
+ pn_transport_bind(e->transport, e->connection);
pn_collector_pop(e->collector);
+ }
e->event = pn_collector_peek(e->collector);
log_event(e, e->event);
return e->event;