Ported ReadN, but need to get things working

This commit is contained in:
saxon 2018-07-28 14:55:25 +09:30
parent 6a6f704840
commit 80cc24f665
1 changed files with 40 additions and 21 deletions

View File

@ -754,7 +754,7 @@ func handShake(r *C.RTMP, FP9HandShake int32) int {
}
// TODO: port this
if readN(r, (*C.char)(unsafe.Pointer(&typ)), 1) != 1 {
if readN(r, (*byte)(unsafe.Pointer(&typ)), 1) != 1 {
return 0
}
@ -796,8 +796,6 @@ func handShake(r *C.RTMP, FP9HandShake int32) int {
return 1
}
// TODO: complete this
/*
func readN(r *C.RTMP, buffer *byte, n int) int {
nOriginalSize := n
var avail int
@ -810,29 +808,50 @@ func readN(r *C.RTMP, buffer *byte, n int) int {
for n > 0 {
nBytes := 0
var nRead int
if r.Link.protocol & RTMP_FEATURE_HTTP {
refill := 0
for r.m_resplen == 0 {
var ret int
if r.m_sb.sb_size < 13 || refill {
if r.m_unackd == 0 {
C.HTTP_Post(r, RTMPT_IDLE, "", 1)
}
if C.RTMPSockBuf_Fill(&r.m_sb) < 1){
if r.m_sb.sb_timedout == 0 {
return 0
}
}
avail = int(r.m_sb.sb_size)
if avail == 0 {
if C.RTMPSockBuf_Fill(&r.m_sb) < 1 {
if r.m_sb.sb_timedout == 0 {
return 0
}
}
}
}
}
*/
if n < avail {
nRead = n
} else {
nRead = avail
}
if nRead > 0 {
memmove(unsafe.Pointer(ptr), unsafe.Pointer(r.m_sb.sb_start), uintptr(nRead))
r.m_sb.sb_start = (*C.char)(incBytePtr(unsafe.Pointer(r.m_sb.sb_start),
nRead))
r.m_sb.sb_size -= C.int(nRead)
nBytes = nRead
r.m_nBytesIn += C.int(nRead)
if r.m_bSendCounter != 0 && r.m_nBytesIn > (r.m_nBytesInSent+
r.m_nClientBW/10) {
// TODO: port this
if C.SendBytesReceived(r) == 0 {
return 0
}
}
}
if nBytes == 0 {
log.Println("RTMP socket closed by peer")
// RTMP_Close(r)
break
}
n -= nBytes
ptr = (*byte)(incBytePtr(unsafe.Pointer(ptr), nBytes))
}
return nOriginalSize - n
}
func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int {
var packet C.RTMPPacket