rtmp: clarify C_RTMPSockBuf_Fill

The while loop in the C is only there to allow sigint to be caught and
ignored when user interupts are not allowed.
This commit is contained in:
Dan Kortschak 2018-09-19 10:38:11 +09:30
parent 0cfabbbad0
commit 9b5d62a99a
1 changed files with 15 additions and 16 deletions

View File

@ -54,6 +54,7 @@ import (
"math/rand" "math/rand"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -1795,29 +1796,27 @@ func C_CloseInternal(r *C_RTMP, reconnect int32) {
// int RTMPSockBuf_Fill(RTMPSockBuf* sb); // int RTMPSockBuf_Fill(RTMPSockBuf* sb);
// rtmp.c +4253 // rtmp.c +4253
func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int { func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
var nBytes int
if sb.sb_size == 0 { if sb.sb_size == 0 {
sb.sb_start = &sb.sb_buf[0] sb.sb_start = &sb.sb_buf[0]
} }
for { nBytes := C.long(unsafe.Sizeof(sb.sb_buf)) - 1 - C.long(sb.sb_size) -
nBytes = int(unsafe.Sizeof(sb.sb_buf)) - 1 - int(sb.sb_size) - C.long(uintptr(unsafe.Pointer(sb.sb_start))-uintptr(unsafe.Pointer(
int(uintptr(unsafe.Pointer(sb.sb_start))-uintptr(unsafe.Pointer( &sb.sb_buf[0])))
&sb.sb_buf[0])))
// TODO: figure out what to do with recv nBytes, err := C.recv(C.int(sb.sb_socket), unsafe.Pointer(uintptr(unsafe.Pointer(
nBytes = int(C.recv(C.int(sb.sb_socket), unsafe.Pointer(uintptr(unsafe.Pointer( sb.sb_start))+uintptr(int(sb.sb_size))), C.size_t(nBytes), 0)
sb.sb_start))+uintptr(int(sb.sb_size))), C.size_t(nBytes), 0)) if nBytes == -1 {
log.Printf("C_RTMPSockBuf_Fill: recv error: %v", err)
if nBytes != -1 { if err == syscall.EWOULDBLOCK || err == syscall.EAGAIN {
sb.sb_size += int32(nBytes) sb.sb_timedout = 1
} else { nBytes = 0
log.Println("C_RTMPSockBuf_Fill: recv error!")
} }
break } else {
sb.sb_size += int32(nBytes)
} }
return nBytes
return int(nBytes)
} }
// int RTMPSockBuf_Send(RTMPSockBuf* sb, const char* buf, int len); // int RTMPSockBuf_Send(RTMPSockBuf* sb, const char* buf, int len);