diff options
-rw-r--r-- | netaddr.go | 7 | ||||
-rw-r--r-- | network.go | 8 | ||||
m--------- | salticidae | 0 |
3 files changed, 13 insertions, 2 deletions
@@ -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 } @@ -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 -Subproject 8d242e0112c7f9072600a48366ebbd6ce7b5c72 +Subproject 5f617d88a399f276133b4187eb31ca49e5f1338 |