I have to projects. One is cgo and one is C application.
The cgo has a function which needs to return pointer to struct.
The C app receives this pointer and then calls other function in cgo with this pointer.
//export Eb_TcpSecureStreamCreateListener
func Eb_TcpSecureStreamCreateListener(listenIp string, listenPort int) unsafe.Pointer {
pmap := &ThreadSafePeerMap{
peerMap: make(map[string]*Peer, 0),
Mutex: sync.RWMutex{},
}
server := &Server{
ID: cert.Subject.CommonName,
listenAddress: listenIp + ":" + strconv.Itoa(listenPort),
libSecConn: secConn,
PeerMap: pmap,
InboundChannel: make(chan *TcpMessage, channelSize),
OutgoingChannel: make(chan *TcpMessage, channelSize),
ClosedConnections: make(chan *TcpMessage, channelSize),
shutdown: false,
}
server.listener = secConn.NewListener(server.listenAddress, server.ID)
return unsafe.Pointer(server)
}
C code calls this cgo function with the returned unsafe.Pointer:
func Eb_TcpSecureStreamCloseListener(listenerHandle unsafe.Pointer) (retStatus int) {
if listenerHandle == nil {
return C.BadInput
}
server := *(*Server)(listenerHandle)
err := server.listener.Close()
if err != nil {
return C.Error
}
return C.Success
}
My problem is that Eb_TcpSecureStreamCreateListener() return statement cause panic: "runtime error: cgo result has Go pointer"
Any help would be great.
Thanks,