You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by cl...@apache.org on 2016/06/03 20:00:49 UTC

qpid-proton git commit: PROTON-1194: use consistent argument handling, clarify sender flow logic

Repository: qpid-proton
Updated Branches:
  refs/heads/master 3f0edd878 -> e6b068219


PROTON-1194: use consistent argument handling, clarify sender flow logic


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

Branch: refs/heads/master
Commit: e6b06821914a38ad3aa28ac5ea90f432fe7f1c8d
Parents: 3f0edd8
Author: Clifford Jansen <cl...@apache.org>
Authored: Fri Jun 3 12:52:25 2016 -0700
Committer: Clifford Jansen <cl...@apache.org>
Committed: Fri Jun 3 12:52:25 2016 -0700

----------------------------------------------------------------------
 examples/cpp/flow_control.cpp | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e6b06821/examples/cpp/flow_control.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/flow_control.cpp b/examples/cpp/flow_control.cpp
index 24776d7..99f832d 100644
--- a/examples/cpp/flow_control.cpp
+++ b/examples/cpp/flow_control.cpp
@@ -19,6 +19,8 @@
  *
  */
 
+#include "options.hpp"
+
 #include <proton/listener.hpp>
 #include <proton/connection.hpp>
 #include <proton/connection_options.hpp>
@@ -57,10 +59,7 @@ class flow_sender : public proton::messaging_handler {
   public:
     flow_sender() : available(0), sequence(0) {}
 
-    void on_sendable(proton::sender &s) OVERRIDE {
-        if (verbose)
-            std::cout << "flow_sender in \"on_sendable\" with credit " << s.credit()
-                      << " and " << available << " available messages" << std::endl;
+    void send_available_messages(proton::sender &s) {
         for (int i = sequence; available && s.credit() > 0; i++) {
             std::ostringstream mbody;
             mbody << "flow_sender message " << sequence++;
@@ -70,11 +69,18 @@ class flow_sender : public proton::messaging_handler {
         }
     }
 
+    void on_sendable(proton::sender &s) OVERRIDE {
+        if (verbose)
+            std::cout << "flow_sender in \"on_sendable\" with credit " << s.credit()
+                      << " and " << available << " available messages" << std::endl;
+        send_available_messages(s);
+    }
+
     void on_sender_drain_start(proton::sender &s) OVERRIDE {
         if (verbose)
             std::cout << "flow_sender in \"on_drain_start\" with credit " << s.credit()
-                      << " making an internal call to \"on_sendble\"" << std::endl;
-        on_sendable(s); // send as many as we can
+                      << " and " << available << " available messages" << std::endl;
+        send_available_messages(s);
         if (s.credit()) {
             s.return_credit(); // return the rest
         }
@@ -213,15 +219,21 @@ class flow_control : public proton::messaging_handler {
 };
 
 int main(int argc, char **argv) {
-    std::string quiet_arg("-quiet");
-    if (argc > 2 && quiet_arg == argv[2])
-        verbose = false;
+    // Pick an "unusual" port since we are going to be talking to
+    // ourselves, not a broker.
+    std::string address("127.0.0.1:8888");
+    bool quiet = false;
+
+    example::options opts(argc, argv);
+    opts.add_value(address, 'a', "address", "connect and send to URL", "URL");
+    opts.add_flag(quiet, 'q', "quiet", "suppress additional commentary of credit allocation and consumption");
+
     try {
-        // Pick an "unusual" port since we are going to be talking to
-        // ourselves, not a broker.
-        std::string url = argc > 1 ? argv[1] : "127.0.0.1:8888/examples";
+        opts.parse();
+        if (quiet)
+            verbose = false;
 
-        flow_control fc(url);
+        flow_control fc(address);
         proton::default_container(fc).run();
 
         return 0;


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