From 7d9d4639b93abafb0a3159bf6d6186c8ea9ebdb0 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 28 Jul 2018 16:28:24 +0930 Subject: [PATCH] Using my sockBufFill - tested and working --- rtmp/rtmp.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 3f675515..5c61e42a 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -821,7 +821,8 @@ func readN(r *C.RTMP, buffer *byte, n int) int { avail = int(r.m_sb.sb_size) if avail == 0 { - if C.RTMPSockBuf_Fill(&r.m_sb) < 1 { + if rtmpSockBufFill(&r.m_sb) < 1 { + // if C.RTMPSockBuf_Fill(&r.m_sb) < 1 { if r.m_sb.sb_timedout == 0 { return 0 } @@ -864,6 +865,31 @@ func readN(r *C.RTMP, buffer *byte, n int) int { return nOriginalSize - n } +func rtmpSockBufFill(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 = int(C.recv(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 += C.int(nBytes) + } else { + log.Println("rtmpSockBufFill: recv error!") + } + break + } + return nBytes +} + func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { var packet C.RTMPPacket var pbuf [4096]byte