我写了一个简单的GoLang函数,它使用http发出HTTP GET请求。客户端并打印响应字符串。然后,我使用以下命令将其导出为.so文件中的C函数。go build -o libapp.so -buildmode=c-shared libapp.go然后使用这个.SO 和 .h,从我的 C 测试程序中调用导出的 Go 函数。以下是我用来编译和构建C测试程序的命令。gcc -o goclient goclient.c ./libapp.so这是GoLang中的CheckConnection功能var file io.Writer//export CheckConnectionfunc CheckConnection() {path := "/opt/logs/gologs.txt"f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)if err != nil { log.Fatal(err) }file = flog.SetOutput(file)log.Print("---------Logging started---------")log.Print("Hello from CheckConnection\r\n")log.Print("CheckConnection creating http.Client: step1")var netTransport = &http.Transport{ Dial: (&net.Dialer{Timeout: 10 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, }log.Print("CheckConnection creating http.Client: step2")var myClient = &http.Client{ Timeout: time.Second * 10, Transport: netTransport,}log.Print("CheckConnection creating http.Client: step3")res,err := myClient.Get("https://www.google.com")log.Print("CheckConnection creating http.Client: step4")if err!= nil {log.Print("Error ",err)}log.Print("CheckConnection creating http.Client: step5")data,_ := ioutil.ReadAll(res.Body)log.Print("CheckConnection creating http.Client: step6")res.Body.Close()log.Print("CheckConnection creating http.Client: step7")log.Print("Resp code ",res.StatusCode)log.Print("Data ",data)defer log.Print("Returning from CheckConnection");}线程在行下方被阻塞,不超时或给出错误 - res,err := myClient.Get("https://www.google.com")当 CheckConnection() 函数从守护进程调用时,就会发生这种情况。如果我从C,C++main()进程调用这个函数,那么它就可以工作了。我在GitHub上报告了同样的问题 https://github.com/golang/go/issues/47077。它具有重现问题的示例代码(示例.zip)。有关可重现的示例代码,请参阅 GitHub 问题 https://github.com/golang/go/issues/47077。
2 回答
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消