mirror of https://bitbucket.org/ausocean/av.git
rtmp: use C.CString
Now GODEBUG=cgocheck=0 is not needed.
This commit is contained in:
parent
d93357bb6f
commit
e5faa396c1
12
rtmp/rtmp.go
12
rtmp/rtmp.go
|
@ -1677,18 +1677,6 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
|
|||
return size
|
||||
}
|
||||
|
||||
// Creates a new C style string from a go string
|
||||
func goStrToCStr(str string) *byte {
|
||||
l := len(str)
|
||||
slice := make([]byte, l+1)
|
||||
ptr := unsafe.Pointer(&[]byte(str)[0])
|
||||
for i := 0; i < l; i++ {
|
||||
slice[i] = (*[_Gi]byte)(ptr)[i]
|
||||
}
|
||||
slice[l] = '\x00'
|
||||
return &slice[0]
|
||||
}
|
||||
|
||||
// incBytePtr returns an unsafe.Pointer to a byte that is inc positive positions
|
||||
// from the passed ptr
|
||||
func incBytePtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
|
||||
|
|
|
@ -53,21 +53,6 @@ var (
|
|||
errMsg = "Obtained: %v, but wanted: %v"
|
||||
)
|
||||
|
||||
func TestGoStrToCStr(t *testing.T) {
|
||||
goStr := "string\000"
|
||||
bStr := goStrToCStr(goStr)
|
||||
|
||||
testData := []byte{'s', 't', 'r', 'i', 'n', 'g', '\000'}
|
||||
|
||||
for i := 0; i < len(goStr); i++ {
|
||||
val := (*[_Gi]byte)(unsafe.Pointer(bStr))[i]
|
||||
testVal := testData[i]
|
||||
if val != testVal {
|
||||
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncPtr(t *testing.T) {
|
||||
// Test how it deals with bytes
|
||||
bytePtr := unsafe.Pointer(&byteArr[arrStart])
|
||||
|
|
|
@ -56,7 +56,8 @@ import (
|
|||
// int add_addr_info(struct sockaddr_in *service, AVal *host, int port)
|
||||
// rtmp.c +869
|
||||
func C_add_addr_info(service *C.sockaddr_in, hostname string, port uint16) (ok bool) {
|
||||
h := (*C.char)(unsafe.Pointer(goStrToCStr(hostname)))
|
||||
h := C.CString(hostname)
|
||||
defer C.free(unsafe.Pointer(h))
|
||||
service.sin_addr.s_addr = C.inet_addr(h)
|
||||
if service.sin_addr.s_addr == C.INADDR_NONE {
|
||||
host := C.gethostbyname(h)
|
||||
|
|
Loading…
Reference in New Issue