You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/11/02 02:53:23 UTC
[03/50] [abbrv] qpid-proton git commit: PROTON-1255:
connection_engine separate bind from _init
PROTON-1255: connection_engine separate bind from _init
SASL/SSL properties must be set on connection and transport *before* the
pn_transport_bind() call, move it out of pn_connection_engine_init() and add
pn_connection_engine_start() that must be called before using the engine but
after security (and other) properties are set.
Updated the Go and C++ engines accordingly.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3d9fe620
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3d9fe620
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3d9fe620
Branch: refs/heads/go1
Commit: 3d9fe620758bd55afae6af76b50a2bd5d6839232
Parents: b4d0912
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Sep 6 12:39:36 2016 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Sep 20 17:39:15 2016 -0400
----------------------------------------------------------------------
.../bindings/cpp/src/io/connection_engine.cpp | 1 +
.../go/src/qpid.apache.org/proton/engine.go | 2 +
proton-c/include/proton/connection_engine.h | 40 ++++++++++++++------
proton-c/src/engine/connection_engine.c | 17 +++++----
4 files changed, 40 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d9fe620/proton-c/bindings/cpp/src/io/connection_engine.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/io/connection_engine.cpp b/proton-c/bindings/cpp/src/io/connection_engine.cpp
index 4712b3e..d3f2667 100644
--- a/proton-c/bindings/cpp/src/io/connection_engine.cpp
+++ b/proton-c/bindings/cpp/src/io/connection_engine.cpp
@@ -65,6 +65,7 @@ void connection_engine::configure(const connection_options& opts) {
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() {
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d9fe620/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go
----------------------------------------------------------------------
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 3cc6524..bfcb41c 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
@@ -248,6 +248,8 @@ func (eng *Engine) Disconnect(err error) {
// 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)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d9fe620/proton-c/include/proton/connection_engine.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/connection_engine.h b/proton-c/include/proton/connection_engine.h
index cf5006b..b1476c7 100644
--- a/proton-c/include/proton/connection_engine.h
+++ b/proton-c/include/proton/connection_engine.h
@@ -43,16 +43,21 @@
/// Summary of use:
///
/// - while !pn_connection_engine_finished()
+/// - Call pn_connection_engine_dispatch() to dispatch events until it returns NULL.
/// - Read data from your source into pn_connection_engine_read_buffer()
/// - Call pn_connection_engine_read_done() when complete.
/// - Write data from pn_connection_engine_write_buffer() to your destination.
/// - Call pn_connection_engine_write_done() to indicate how much was written.
-/// - Call pn_connection_engine_dispatch() to dispatch events until it returns NULL.
///
-/// Note on error handling: most of the pn_connection_engine_*() functions do
-/// not return an error code. If a fatal error occurs, the transport error
-/// condition will be set and the next call to pn_connection_engine_dispatch()
-/// report it to the handler as a PN_TRANSPORT_ERROR event and return false.
+/// Note on blocking: the _read/write_buffer and _read/write_done functions can
+/// all generate events that may cause the engine to finish. Before you wait for
+/// IO, always drain pn_connection_engine_dispatch() till it returns NULL and
+/// check pn_connection_engine_finished() in case there is nothing more to do..
+///
+/// Note on error handling: the pn_connection_engine_*() functions do not return
+/// an error code. If an error occurs it will be reported as a
+/// PN_TRANSPORT_ERROR event and pn_connection_engine_finished() will return
+/// true once all final events have been processed.
///
/// @defgroup connection_engine The Connection Engine
/// @{
@@ -79,16 +84,27 @@ typedef struct pn_connection_engine_t {
pn_event_t* event;
} pn_connection_engine_t;
-/// Initialize a pn_connection_engine_t struct with a new connection, transport
-/// and collector. Return 0 on success, a proton error code on failure.
+/// 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);
-/// Release the connection, transport and collector associated with engine, set all the pointers
-/// to NULL. Only call on an engine that was initialized with pn_connection_engine_init
+/// 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);
-/// The engine's read buffer. Read data from your IO source to buf.start, up to
-/// a max of buf.size. Then call pn_connection_engine_read_done().
+/// Get the engine's read buffer. Read data from your IO source to buf.start, up
+/// to a max of buf.size. Then call pn_connection_engine_read_done().
///
/// buf.size==0 means the engine cannot read presently, calling
/// pn_connection_engine_dispatch() may create more buffer space.
@@ -104,7 +120,7 @@ PN_EXTERN void pn_connection_engine_read_done(pn_connection_engine_t*, size_t n)
/// in pn_connection_engine_write_buffer()
PN_EXTERN void pn_connection_engine_read_close(pn_connection_engine_t*);
-/// The engine's write buffer. Write data from buf.start to your IO destination,
+/// Get the engine's write buffer. Write data from buf.start to your IO destination,
/// up to a max of buf.size. Then call pn_connection_engine_write_done().
///
/// buf.size==0 means the engine has nothing to write presently. Calling
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d9fe620/proton-c/src/engine/connection_engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/connection_engine.c b/proton-c/src/engine/connection_engine.c
index 41a1bdc..adfb145 100644
--- a/proton-c/src/engine/connection_engine.c
+++ b/proton-c/src/engine/connection_engine.c
@@ -30,19 +30,20 @@ int pn_connection_engine_init(pn_connection_engine_t* e) {
e->collector = pn_collector();
if (!e->connection || !e->transport || !e->collector) {
pn_connection_engine_final(e);
- return PN_ERR;
- }
- int err;
- // Bind before collect: don't expose the connection until it has a transport.
- err = pn_transport_bind(e->transport, e->connection);
- if (err) {
- pn_connection_engine_final(e);
- return err;
+ return PN_OUT_OF_MEMORY;
}
pn_connection_collect(e->connection, e->collector);
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);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org