From bbd7fad4b9fc657780fa35dcdc979e72200eb053 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sat, 29 Jun 2019 16:35:32 -0400 Subject: fix the cgo bug --- netaddr.go | 7 ++++++- network.go | 8 +++++++- salticidae | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/netaddr.go b/netaddr.go index 1b2eb63..7955334 100644 --- a/netaddr.go +++ b/netaddr.go @@ -39,14 +39,19 @@ func NewAddrFromIPPortString(addr string, err *Error) (res NetAddr) { // Convert a Go slice of net addresses to NetAddrArray. func NewAddrArrayFromAddrs(arr []NetAddr) (res NetAddrArray) { size := len(arr) + _arr := make([]CNetAddr, size) + for i, v := range arr { + _arr[i] = v.inner + } if size > 0 { // FIXME: here we assume struct of a single pointer has the same memory // footprint the pointer - base := (**C.netaddr_t)(rawptr_t(&arr[0])) + base := (**C.netaddr_t)(rawptr_t(&_arr[0])) res = &netAddrArray{ inner: C.netaddr_array_new_from_addrs(base, C.size_t(size)) } } else { res = &netAddrArray{ inner: C.netaddr_array_new() } } + runtime.KeepAlive(_arr) runtime.SetFinalizer(res, func(self NetAddrArray) { self.free() }) return } diff --git a/network.go b/network.go index 71e0ffa..e97821b 100644 --- a/network.go +++ b/network.go @@ -33,7 +33,6 @@ func MsgNetworkConnFromC(ptr CMsgNetworkConn) MsgNetworkConn { var ( CONN_MODE_ACTIVE = MsgNetworkConnMode(C.CONN_MODE_ACTIVE) CONN_MODE_PASSIVE = MsgNetworkConnMode(C.CONN_MODE_PASSIVE) - CONN_MODE_DEAD = MsgNetworkConnMode(C.CONN_MODE_DEAD) ) // The connection mode. CONN_MODE_ACTIVE: a connection established from the @@ -386,6 +385,13 @@ func (self PeerNetworkConn) Copy() PeerNetworkConn { return res } +// Get the listening address of the remote peer (no Copy() is needed). +func (self PeerNetworkConn) GetPeerAddr() NetAddr { + res := NetAddrFromC(C.peernetwork_conn_get_peer_addr(self.inner)) + runtime.SetFinalizer(res, func(self NetAddr) { self.free() }) + return res +} + func (self PeerNetworkConn) free() { C.peernetwork_conn_free(self.inner) } // Listen to the specified network address. Notice that this method overrides diff --git a/salticidae b/salticidae index 8d242e0..5f617d8 160000 --- a/salticidae +++ b/salticidae @@ -1 +1 @@ -Subproject commit 8d242e0112c7f9072600a48366ebbd6ce7b5c727 +Subproject commit 5f617d88a399f276133b4187eb31ca49e5f1338a -- cgit v1.2.3-70-g09d2