qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1179: c++: Update connection_engine to use error_condition.
Date Fri, 22 Apr 2016 16:29:07 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 27cea74f9 -> 6fabb14ce


PROTON-1179: c++: Update connection_engine to use error_condition.

- connection_engine::close uses error_condition.
- moved set_error_condition() to error_condition::set(pn_condition_t*)
  to make it accessible to connection_engine
- added error_condition op==, op<<.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/6fabb14c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/6fabb14c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/6fabb14c

Branch: refs/heads/master
Commit: 6fabb14ce6e906f3c8080699fdcdfd126667a839
Parents: 27cea74
Author: Alan Conway <aconway@redhat.com>
Authored: Fri Apr 22 09:50:16 2016 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Fri Apr 22 12:23:47 2016 -0400

----------------------------------------------------------------------
 .../cpp/include/proton/error_condition.hpp      |  5 +++
 .../cpp/include/proton/io/connection_engine.hpp | 11 +++---
 proton-c/bindings/cpp/src/endpoint.cpp          | 37 ++++++++------------
 proton-c/bindings/cpp/src/engine_test.cpp       | 26 +++++++++++---
 proton-c/bindings/cpp/src/error_condition.cpp   |  9 +++++
 .../bindings/cpp/src/io/connection_engine.cpp   | 10 +++---
 proton-c/bindings/cpp/src/io/posix/socket.cpp   |  7 ++--
 proton-c/bindings/cpp/src/proton_bits.cpp       | 24 ++++++++++++-
 proton-c/bindings/cpp/src/proton_bits.hpp       | 14 +++++---
 9 files changed, 100 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/include/proton/error_condition.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/error_condition.hpp b/proton-c/bindings/cpp/include/proton/error_condition.hpp
index 0d109dc..0da428d 100644
--- a/proton-c/bindings/cpp/include/proton/error_condition.hpp
+++ b/proton-c/bindings/cpp/include/proton/error_condition.hpp
@@ -28,6 +28,7 @@
 #include "proton/config.hpp"
 
 #include <string>
+#include <iosfwd>
 
 struct pn_condition_t;
 
@@ -86,6 +87,10 @@ class error_condition {
     /// @endcond
 };
 
+PN_CPP_EXTERN bool operator==(const error_condition& x, const error_condition& y);
+
+PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const error_condition&
err);
+
 }
 
 #endif // PROTON_CPP_ERROR_CONDITION_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp b/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
index 42ab06e..acf47fa 100644
--- a/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
+++ b/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
@@ -146,10 +146,10 @@ PN_CPP_CLASS_EXTERN connection_engine {
     /// Indicate that the write side of the transport has closed and no more data will be
written.
     PN_CPP_EXTERN void write_close();
 
-    /// Indicate that the transport has closed with an error condition.
-    /// This calls both read_close() and write_close().
-    /// The error condition will be passed to handler::on_transport_error()
-    PN_CPP_EXTERN void close(const std::string& name, const std::string& description);
+    /// Close the engine with an error that will be passed to handler::on_transport_error().
+    /// Calls read_close() and write_close().
+    /// Note: You still need to call dispatch() to process final close-down events.
+    PN_CPP_EXTERN void close(const error_condition&);
 
     /// Dispatch all available events and call the corresponding \ref handler methods.
     ///
@@ -168,6 +168,9 @@ PN_CPP_CLASS_EXTERN connection_engine {
     /// Get the AMQP connection associated with this connection_engine.
     PN_CPP_EXTERN proton::connection connection() const;
 
+    /// Get the transport associated with this connection_engine.
+    PN_CPP_EXTERN proton::transport transport() const;
+
   private:
     connection_engine(const connection_engine&);
     connection_engine& operator=(const connection_engine&);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/endpoint.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/endpoint.cpp b/proton-c/bindings/cpp/src/endpoint.cpp
index c70edbf..60d9355 100644
--- a/proton-c/bindings/cpp/src/endpoint.cpp
+++ b/proton-c/bindings/cpp/src/endpoint.cpp
@@ -18,13 +18,13 @@
  * under the License.
  *
  */
-
-#include "proton/endpoint.hpp"
+#include "proton_bits.hpp"
 
 #include "proton/connection.hpp"
+#include "proton/endpoint.hpp"
 #include "proton/error_condition.hpp"
-#include "proton/session.hpp"
 #include "proton/link.hpp"
+#include "proton/session.hpp"
 
 #include "proton/connection.h"
 #include "proton/session.h"
@@ -35,22 +35,6 @@ namespace {
 inline bool uninitialized(int state) { return state & PN_LOCAL_UNINIT; }
 inline bool active(int state) { return state & PN_LOCAL_ACTIVE; }
 inline bool closed(int state) { return (state & PN_LOCAL_CLOSED) && (state &
PN_REMOTE_CLOSED); }
-
-inline void set_condition(pn_condition_t *c, const proton::error_condition &e) {
-    pn_condition_clear(c);
-
-    if (!e.name().empty()) {
-        pn_condition_set_name(c, e.name().c_str());
-    }
-    if (!e.description().empty()) {
-        pn_condition_set_description(c, e.description().c_str());
-    }
-    // TODO: This is wrong as it copies the value so doesn't change
-    // The internals of c
-    //proton::value v(pn_condition_info(c));
-    //v = e.properties();
-}
-
 }
 
 namespace proton {
@@ -59,19 +43,28 @@ bool connection::uninitialized() const { return ::uninitialized(pn_connection_st
 bool connection::active() const { return ::active(pn_connection_state(pn_object())); }
 bool connection::closed() const { return ::closed(pn_connection_state(pn_object())); }
 
-void connection::close(const error_condition& condition) { ::set_condition(pn_connection_condition(pn_object()),
condition); close(); }
+void connection::close(const error_condition& condition) {
+    set_error_condition(condition, pn_connection_condition(pn_object()));
+    close();
+}
 
 bool session::uninitialized() const { return ::uninitialized(pn_session_state(pn_object()));
}
 bool session::active() const { return ::active(pn_session_state(pn_object())); }
 bool session::closed() const { return ::closed(pn_session_state(pn_object())); }
 
-void session::close(const error_condition& condition) { ::set_condition(pn_session_condition(pn_object()),
condition); close(); }
+void session::close(const error_condition& condition) {
+    set_error_condition(condition, pn_session_condition(pn_object()));
+    close();
+}
 
 bool link::uninitialized() const { return ::uninitialized(pn_link_state(pn_object())); }
 bool link::active() const { return ::active(pn_link_state(pn_object())); }
 bool link::closed() const { return ::closed(pn_link_state(pn_object())); }
 
-void link::close(const error_condition& condition) { ::set_condition(pn_link_condition(pn_object()),
condition); close(); }
+void link::close(const error_condition& condition) {
+    set_error_condition(condition, pn_link_condition(pn_object()));
+    close();
+}
 
 endpoint::~endpoint() {}
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/engine_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/engine_test.cpp b/proton-c/bindings/cpp/src/engine_test.cpp
index 3bb154f..8c2385d 100644
--- a/proton-c/bindings/cpp/src/engine_test.cpp
+++ b/proton-c/bindings/cpp/src/engine_test.cpp
@@ -97,7 +97,7 @@ template <class S> typename S::value_type quick_pop(S& s) {
 struct record_handler : public handler {
     std::deque<proton::link> links;
     std::deque<proton::session> sessions;
-    std::deque<std::string> errors;
+    std::deque<std::string> errors, transport_errors, connection_errors;
 
     void on_receiver_open(receiver &l) override {
         links.push_back(l);
@@ -111,6 +111,14 @@ struct record_handler : public handler {
         sessions.push_back(s);
     }
 
+    void on_transport_error(transport& t) override {
+        transport_errors.push_back(t.error().what());
+    }
+
+    void on_connection_error(connection& c) override {
+        connection_errors.push_back(c.error().what());
+    }
+
     void on_unhandled_error(const proton::error_condition& c) override {
         errors.push_back(c.what());
     }
@@ -213,6 +221,8 @@ void test_endpoint_close() {
     ca.close(proton::error_condition("conn", "bad connection"));
     while (!cb.closed()) e.process();
     ASSERT_EQUAL("conn: bad connection", cb.error().what());
+    ASSERT_EQUAL(1, hb.connection_errors.size());
+    ASSERT_EQUAL("conn: bad connection", hb.connection_errors.front());
 }
 
 void test_transport_close() {
@@ -222,14 +232,20 @@ void test_transport_close() {
     e.a.connection().open();
     while (!e.b.connection().active()) e.process();
 
-    e.a.close("oops", "engine failure");
+    e.a.close(proton::error_condition("oops", "engine failure"));
     // Closed but we still have output data to flush so a.dispatch() is true.
     ASSERT(e.a.dispatch());
-    while (!e.b.connection().closed()) e.process();
+    do { e.process(); } while (e.b.dispatch());
     ASSERT_EQUAL(1, hb.errors.size());
     ASSERT_EQUAL("oops: engine failure", hb.errors.front());
-    ASSERT_EQUAL("oops", e.b.connection().error().name());
-    ASSERT_EQUAL("engine failure", e.b.connection().error().description());
+    // Connection and transport share the same error.
+    ASSERT_EQUAL(proton::error_condition("oops", "engine failure"),e.b.connection().error());
+    ASSERT_EQUAL(proton::error_condition("oops", "engine failure"),e.b.transport().error());
+    // But connectoin was never protocol closed.
+    ASSERT(!e.b.connection().closed());
+    ASSERT_EQUAL(0, hb.connection_errors.size());
+    ASSERT_EQUAL(1, hb.transport_errors.size());
+    ASSERT_EQUAL("oops: engine failure", hb.transport_errors.front());
 }
 
 int main(int, char**) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/error_condition.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/error_condition.cpp b/proton-c/bindings/cpp/src/error_condition.cpp
index 247941f..07abddb 100644
--- a/proton-c/bindings/cpp/src/error_condition.cpp
+++ b/proton-c/bindings/cpp/src/error_condition.cpp
@@ -84,4 +84,13 @@ std::string error_condition::what() const {
     }
 }
 
+bool operator==(const error_condition& x, const error_condition& y) {
+    return x.name() == y.name() && x.description() == y.description()
+        && x.properties() == y.properties();
+}
+
+std::ostream& operator<<(std::ostream& o, const error_condition& err) {
+    return o << err.what();
+}
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/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 b3aa223..e2a9356 100644
--- a/proton-c/bindings/cpp/src/io/connection_engine.cpp
+++ b/proton-c/bindings/cpp/src/io/connection_engine.cpp
@@ -147,10 +147,8 @@ void connection_engine::write_close() {
     pn_transport_close_head(transport_.pn_object());
 }
 
-void connection_engine::close(const std::string& name, const std::string& description)
{
-    pn_condition_t* c = pn_transport_condition(transport_.pn_object());
-    pn_condition_set_name(c, name.c_str());
-    pn_condition_set_description(c, description.c_str());
+void connection_engine::close(const proton::error_condition& err) {
+    set_error_condition(err, pn_transport_condition(transport_.pn_object()));
     read_close();
     write_close();
 }
@@ -159,4 +157,8 @@ proton::connection connection_engine::connection() const {
     return connection_;
 }
 
+proton::transport connection_engine::transport() const {
+    return transport_;
+}
+
 }}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/io/posix/socket.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/io/posix/socket.cpp b/proton-c/bindings/cpp/src/io/posix/socket.cpp
index e275288..204b530 100644
--- a/proton-c/bindings/cpp/src/io/posix/socket.cpp
+++ b/proton-c/bindings/cpp/src/io/posix/socket.cpp
@@ -19,6 +19,7 @@
 
 #include "msg.hpp"
 
+#include <proton/error_condition.hpp>
 #include <proton/io/socket.hpp>
 #include <proton/url.hpp>
 
@@ -92,7 +93,7 @@ void engine::read() {
         else if (n == 0)
             read_close();
         else if (n < 0 && errno != EAGAIN && errno != EWOULDBLOCK)
-            close("io_error", error_str());
+            close(error_condition("io_error", error_str()));
     }
 }
 
@@ -103,7 +104,7 @@ void engine::write() {
         if (n > 0)
             write_done(n);
         else if (n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
-            close("io_error", error_str());
+            close(error_condition("io_error", error_str()));
         }
     }
 }
@@ -119,7 +120,7 @@ void engine::run() {
             FD_SET(socket_, &wr);
         int n = ::select(FD_SETSIZE, &rd, &wr, NULL, NULL);
         if (n < 0) {
-            close("select: ", error_str());
+            close(error_condition("select: ", error_str()));
             break;
         }
         if (FD_ISSET(socket_, &rd)) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/proton_bits.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proton_bits.cpp b/proton-c/bindings/cpp/src/proton_bits.cpp
index 0d41da8..af032c9 100644
--- a/proton-c/bindings/cpp/src/proton_bits.cpp
+++ b/proton-c/bindings/cpp/src/proton_bits.cpp
@@ -17,11 +17,16 @@
  * under the License.
  */
 
+#include "proton_bits.hpp"
+
 #include <string>
 #include <ostream>
+
+#include <proton/condition.h>
 #include <proton/error.h>
 #include <proton/object.h>
-#include "proton_bits.hpp"
+
+namespace proton {
 
 std::string error_str(long code) {
   switch (code)
@@ -54,3 +59,20 @@ std::ostream& operator<<(std::ostream& o, const inspectable&
object) {
     pn_free(str);
     return o;
 }
+
+void set_error_condition(const error_condition& e, pn_condition_t *c) {
+    pn_condition_clear(c);
+
+    if (!e.name().empty()) {
+        pn_condition_set_name(c, e.name().c_str());
+    }
+    if (!e.description().empty()) {
+        pn_condition_set_description(c, e.description().c_str());
+    }
+    // TODO: This is wrong as it copies the value so doesn't change
+    // The internals of c
+    //proton::value v(pn_condition_info(c));
+    //v = e.properties();
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fabb14c/proton-c/bindings/cpp/src/proton_bits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proton_bits.hpp b/proton-c/bindings/cpp/src/proton_bits.hpp
index 6ba0848..a53eaf0 100644
--- a/proton-c/bindings/cpp/src/proton_bits.hpp
+++ b/proton-c/bindings/cpp/src/proton_bits.hpp
@@ -1,5 +1,5 @@
-#ifndef ERROR_H
-#define ERROR_H
+#ifndef PROTON_BITS_HPP
+#define PROTON_BITS_HPP
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,6 +21,7 @@
 
 #include <string>
 #include <iosfwd>
+#include <proton/error_condition.hpp>
 #include <proton/error.h>
 
 /**@file
@@ -28,6 +29,10 @@
  * Assorted internal proton utilities.
  */
 
+namespace proton {
+
+class error_condition;
+
 std::string error_str(long code);
 
 /** Print the error string from pn_error_t, or from code if pn_error_t has no error. */
@@ -39,7 +44,8 @@ struct inspectable { void* value; inspectable(void* o) : value(o) {} };
 /** Stream a proton object via pn_inspect. */
 std::ostream& operator<<(std::ostream& o, const inspectable& object);
 
+void set_error_condition(const error_condition&, pn_condition_t*);
 
+}
 
-
-#endif // ERROR_H
+#endif // PROTON_BITS_HPP


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message