Hi,

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.
I build the cgo as shared lib: 


*go build -o ebsdk.so -buildmode=c-shared*
The cgo function is this:

//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,



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to