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