This is an automated email from the ASF dual-hosted git repository.

aconway pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 8e15ea408952a00e819873c2bb90d7a922624f8a
Author: Alan Conway <acon...@redhat.com>
AuthorDate: Tue Dec 18 13:03:27 2018 -0500

    PROTON-985: [go] Go binding uses monotonic clock
    
    Updated generated code for new pn_proton_tick() signature,
    Updated binding to use monotonic time.
---
 go/genwrap.go                                 | 22 ++++++++++++--
 go/src/qpid.apache.org/amqp/version.go        |  2 +-
 go/src/qpid.apache.org/proton/engine.go       | 15 ++++++++--
 go/src/qpid.apache.org/proton/wrappers_gen.go | 43 +++++++++++++++++++++++++--
 4 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/go/genwrap.go b/go/genwrap.go
index 5848905..b7cd6c0 100644
--- a/go/genwrap.go
+++ b/go/genwrap.go
@@ -43,8 +43,13 @@ import (
        "text/template"
 )
 
-var minVersion = "0.10" // The minimum version of proton-c that the Go binding 
can use
-var include = flag.String("include", "../../c/include", "Directory containing 
proton/*.h include files")
+// Note last code generation was from 0.27 source, but we should still
+// be binary compatible back to 0.10. Only change was the type name
+// for pn_proton_tick() from pn_timestamp_t to int64_t, identical type.
+
+var minVersion = "0.27" // The proton-c header version last used to generate 
code
+
+var include = flag.String("include", "../c/include", "Directory containing 
proton/*.h include files")
 
 var versionH = regexp.MustCompile("(?s:PN_VERSION_MAJOR 
([0-9]+).*PN_VERSION_MINOR ([0-9]+))")
 var versionTxt = regexp.MustCompile("^[0-9]+\\.[0-9]+")
@@ -74,7 +79,7 @@ func getVersion() string {
 func genVersion() {
        version := getVersion()
        if minVersion != version {
-               panic(fmt.Errorf("Generating from wrong version %v, expected 
%v", version, minVersion))
+               panic(fmt.Errorf("Found proton-c version %v, expected %v. 
Update minVersion in genwrap.go if you want to increase the minimum required 
proton-c version.", version, minVersion))
        }
        out, err := os.Create("src/qpid.apache.org/amqp/version.go")
        panicIf(err)
@@ -344,6 +349,12 @@ func mapType(ctype string) (g genType) {
                g.Gotype = "bool"
        case "C.ssize_t":
                g.Gotype = "int"
+       case "C.int64_t":
+               g.Gotype = "int64"
+       case "C.int32_t":
+               g.Gotype = "int16"
+       case "C.int16_t":
+               g.Gotype = "int32"
        case "C.uint64_t":
                g.Gotype = "uint64"
        case "C.uint32_t":
@@ -463,6 +474,11 @@ func goFnName(api, fname string) string {
 }
 
 func apiWrapFns(api, header string, out io.Writer) {
+       defer func() {
+               if err := recover(); err != nil {
+                       panic(fmt.Sprintf("in %s.h: %s", api, err))
+               }
+       }()
        fmt.Fprintf(out, "type %s struct{pn *C.pn_%s_t}\n", mixedCase(api), api)
        fmt.Fprintf(out, "func (%c %s) IsNil() bool { return %c.pn == nil }\n", 
api[0], mixedCase(api), api[0])
        fmt.Fprintf(out, "func (%c %s) CPtr() unsafe.Pointer { return 
unsafe.Pointer(%c.pn) }\n", api[0], mixedCase(api), api[0])
diff --git a/go/src/qpid.apache.org/amqp/version.go 
b/go/src/qpid.apache.org/amqp/version.go
index bf33d2b..31d69d2 100644
--- a/go/src/qpid.apache.org/amqp/version.go
+++ b/go/src/qpid.apache.org/amqp/version.go
@@ -29,7 +29,7 @@ package amqp
 // Done here because this is the lowest-level dependency for all the proton Go 
packages.
 
 // #include <proton/version.h>
-// #if PN_VERSION_MAJOR == 0 && PN_VERSION_MINOR < 10
+// #if PN_VERSION_MAJOR == 0 && PN_VERSION_MINOR < 27
 // #error packages qpid.apache.org/... require Proton-C library version 0.10 
or greater
 // #endif
 import "C"
diff --git a/go/src/qpid.apache.org/proton/engine.go 
b/go/src/qpid.apache.org/proton/engine.go
index af26a5f..7676543 100644
--- a/go/src/qpid.apache.org/proton/engine.go
+++ b/go/src/qpid.apache.org/proton/engine.go
@@ -262,12 +262,21 @@ func (eng *Engine) log(format string, args 
...interface{}) {
        fmt.Fprintf(os.Stderr, "[%p]: %v", eng.transport, fmt.Sprintf(format, 
args...))
 }
 
+var processStart = time.Now() // Process start time for elapsed()
+
+// Monotonic elapsed time since processStart
+func elapsed() time.Duration {
+       // Time.Sub() uses monotonic time.
+       return time.Now().Sub(processStart)
+}
+
 // Let proton run timed activity and set up the next tick
 func (eng *Engine) tick() {
-       now := time.Now()
+       // Proton wants millisecond monotonic time
+       now := int64(elapsed() / time.Millisecond)
        next := eng.Transport().Tick(now)
-       if !next.IsZero() {
-               eng.timer.Reset(next.Sub(now))
+       if next != 0 {
+               eng.timer.Reset(time.Duration((next - now) * 
int64(time.Millisecond)))
        }
 }
 
diff --git a/go/src/qpid.apache.org/proton/wrappers_gen.go 
b/go/src/qpid.apache.org/proton/wrappers_gen.go
index 0db04c8..a627e60 100644
--- a/go/src/qpid.apache.org/proton/wrappers_gen.go
+++ b/go/src/qpid.apache.org/proton/wrappers_gen.go
@@ -80,6 +80,13 @@ const (
        ETransportHeadClosed    EventType = C.PN_TRANSPORT_HEAD_CLOSED
        ETransportTailClosed    EventType = C.PN_TRANSPORT_TAIL_CLOSED
        ETransportClosed        EventType = C.PN_TRANSPORT_CLOSED
+       EConnectionWake         EventType = C.PN_CONNECTION_WAKE
+       EListenerAccept         EventType = C.PN_LISTENER_ACCEPT
+       EListenerClose          EventType = C.PN_LISTENER_CLOSE
+       EProactorInterrupt      EventType = C.PN_PROACTOR_INTERRUPT
+       EProactorTimeout        EventType = C.PN_PROACTOR_TIMEOUT
+       EProactorInactive       EventType = C.PN_PROACTOR_INACTIVE
+       EListenerOpen           EventType = C.PN_LISTENER_OPEN
 )
 
 func (e EventType) String() string {
@@ -145,6 +152,20 @@ func (e EventType) String() string {
                return "TransportTailClosed"
        case C.PN_TRANSPORT_CLOSED:
                return "TransportClosed"
+       case C.PN_CONNECTION_WAKE:
+               return "ConnectionWake"
+       case C.PN_LISTENER_ACCEPT:
+               return "ListenerAccept"
+       case C.PN_LISTENER_CLOSE:
+               return "ListenerClose"
+       case C.PN_PROACTOR_INTERRUPT:
+               return "ProactorInterrupt"
+       case C.PN_PROACTOR_TIMEOUT:
+               return "ProactorTimeout"
+       case C.PN_PROACTOR_INACTIVE:
+               return "ProactorInactive"
+       case C.PN_LISTENER_OPEN:
+               return "ListenerOpen"
        }
        return "Unknown"
 }
@@ -354,6 +375,15 @@ func (l Link) SetDrain(drain bool) {
 func (l Link) Draining() bool {
        return bool(C.pn_link_draining(l.pn))
 }
+func (l Link) MaxMessageSize() uint64 {
+       return uint64(C.pn_link_max_message_size(l.pn))
+}
+func (l Link) SetMaxMessageSize(size uint64) {
+       C.pn_link_set_max_message_size(l.pn, C.uint64_t(size))
+}
+func (l Link) RemoteMaxMessageSize() uint64 {
+       return uint64(C.pn_link_remote_max_message_size(l.pn))
+}
 
 // Wrappers for declarations in delivery.h
 
@@ -388,6 +418,9 @@ func (d Delivery) Pending() uint {
 func (d Delivery) Partial() bool {
        return bool(C.pn_delivery_partial(d.pn))
 }
+func (d Delivery) Aborted() bool {
+       return bool(C.pn_delivery_aborted(d.pn))
+}
 func (d Delivery) Writable() bool {
        return bool(C.pn_delivery_writable(d.pn))
 }
@@ -406,6 +439,9 @@ func (d Delivery) Clear() {
 func (d Delivery) Current() bool {
        return bool(C.pn_delivery_current(d.pn))
 }
+func (d Delivery) Abort() {
+       C.pn_delivery_abort(d.pn)
+}
 func (d Delivery) Settle() {
        C.pn_delivery_settle(d.pn)
 }
@@ -501,6 +537,9 @@ func (c Condition) RedirectHost() string {
 func (c Condition) RedirectPort() int {
        return int(C.pn_condition_redirect_port(c.pn))
 }
+func (c Condition) Copy(src Condition) int {
+       return int(C.pn_condition_copy(c.pn, src.pn))
+}
 
 // Wrappers for declarations in terminus.h
 
@@ -858,8 +897,8 @@ func (t Transport) Quiesced() bool {
 func (t Transport) Closed() bool {
        return bool(C.pn_transport_closed(t.pn))
 }
-func (t Transport) Tick(now time.Time) time.Time {
-       return goTime(C.pn_transport_tick(t.pn, pnTime(now)))
+func (t Transport) Tick(now int64) int64 {
+       return int64(C.pn_transport_tick(t.pn, C.int64_t(now)))
 }
 func (t Transport) Connection() Connection {
        return Connection{C.pn_transport_connection(t.pn)}


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

Reply via email to