Repository: qpid-proton
Updated Branches:
  refs/heads/master 5639656cf -> cd011b6b2


PROTON-1327: [Go binding] Replaced c handler based flowcontroller with native go
- The go binding now has no dependency on the proton-c reactor code


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

Branch: refs/heads/master
Commit: cd011b6b2927f9a62b63884db723a496d54fe604
Parents: 5639656
Author: Andrew Stitcher <astitc...@apache.org>
Authored: Mon Oct 10 15:31:25 2016 -0400
Committer: Andrew Stitcher <astitc...@apache.org>
Committed: Fri Oct 14 13:39:08 2016 -0400

----------------------------------------------------------------------
 .../go/src/qpid.apache.org/proton/engine.go     |  6 ----
 .../go/src/qpid.apache.org/proton/handlers.go   | 33 +++++++++++---------
 2 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cd011b6b/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 7f1368e..a0b8888 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
@@ -385,12 +385,6 @@ func (eng *Engine) Run() error {
        _ = eng.conn.Close() // Close conn, force read/write goroutines to exit 
(they will Inject)
        wait.Wait()          // Wait for goroutines
 
-       for _, h := range eng.handlers {
-               switch h := h.(type) {
-               case cHandler:
-                       C.pn_handler_free(h.pn)
-               }
-       }
        C.pn_connection_engine_final(&eng.engine)
        return eng.err.Get()
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cd011b6b/proton-c/bindings/go/src/qpid.apache.org/proton/handlers.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/proton/handlers.go 
b/proton-c/bindings/go/src/qpid.apache.org/proton/handlers.go
index 24e5eb3..8213b65 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/proton/handlers.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/proton/handlers.go
@@ -19,8 +19,6 @@ under the License.
 
 package proton
 
-// #include <proton/handlers.h>
-import "C"
 import "fmt"
 
 // EventHandler handles core proton events.
@@ -31,17 +29,6 @@ type EventHandler interface {
        HandleEvent(e Event)
 }
 
-// FIXME aconway 2016-06-21: get rid of C handlers?
-
-// cHandler wraps a C pn_handler_t
-type cHandler struct {
-       pn *C.pn_handler_t
-}
-
-func (h cHandler) HandleEvent(e Event) {
-       C.pn_handler_dispatch(h.pn, e.pn, C.pn_event_type(e.pn))
-}
-
 // MessagingHandler provides an alternative interface to EventHandler.
 // it is easier to use for most applications that send and receive messages.
 //
@@ -239,6 +226,24 @@ func (d endpointDelegator) HandleEvent(e Event) {
        }
 }
 
+type flowcontroller struct {
+       window, drained int
+}
+
+func (d flowcontroller) HandleEvent(e Event) {
+       link := e.Link();
+
+       switch e.Type() {
+       case ELinkLocalOpen, ELinkRemoteOpen, ELinkFlow, EDelivery:
+               if link.IsReceiver() {
+                       d.drained += link.Drained()
+                       if d.drained != 0 {
+                               link.Flow(d.window-link.Credit())
+                       }
+               }
+       }
+}
+
 // MessagingAdapter implments a EventHandler and delegates to a 
MessagingHandler.
 // You can modify the exported fields before you pass the MessagingAdapter to
 // a Engine.
@@ -308,7 +313,7 @@ func (d *MessagingAdapter) HandleEvent(e Event) {
                        d,
                }
                if d.Prefetch > 0 {
-                       d.flowcontroller = 
cHandler{C.pn_flowcontroller(C.int(d.Prefetch))}
+                       d.flowcontroller = flowcontroller{ window:d.Prefetch, 
drained:0 }
                }
                d.mhandler.HandleMessagingEvent(MStart, e)
 


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

Reply via email to