Merged in portable-sockets (pull request #92)

Replaced Unix sockets with IPConn. Sock_XXX funtions have been left as is for PR readability.

Approved-by: Saxon Milton <saxon.milton@gmail.com>
Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
Alan Noble 2019-01-04 20:37:23 +00:00
commit c971d4b225
4 changed files with 11 additions and 23 deletions

View File

@ -490,7 +490,6 @@ func (r *Revid) startRaspivid() error {
// setupInputForFile sets things up for getting input from a file
func (r *Revid) setupInputForFile() error {
delay := time.Second / time.Duration(r.config.FrameRate)
f, err := os.Open(r.config.InputFileName)
if err != nil {
r.config.Logger.Log(logger.Error, err.Error())

View File

@ -140,6 +140,7 @@ type C_RTMPPacket struct {
// rtmp.h +127
type C_RTMPSockBuf struct {
conn *net.TCPConn
timeout int32
sb_size int
sb_start int
sb_buf [RTMP_BUFFER_CACHE_SIZE]byte // port const

View File

@ -37,8 +37,7 @@ import (
"fmt"
"log"
"net"
"golang.org/x/sys/unix"
"time"
)
// int RTMP_Connect(RTMP *r, RTMPPacket* cp);
@ -68,19 +67,8 @@ func C_RTMP_Connect(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
}
}
f, err := r.m_sb.conn.File()
if err != nil {
log.Printf("failed to get fd to set timeout: %v", err)
return false
}
tv := setTimeval(int(r.Link.timeout))
err = unix.SetsockoptTimeval(int(f.Fd()), unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv)
if err != nil {
log.Printf("failed to set timeout: %v", err)
}
r.m_sb.timeout = r.Link.timeout
r.m_bSendCounter = true
return C_RTMP_Connect1(r, cp)
}
@ -116,7 +104,10 @@ func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
if sb.sb_size == 0 {
sb.sb_start = 0
}
err := sb.conn.SetReadDeadline(time.Now().Local().Add(time.Second * time.Duration(sb.timeout)))
if err != nil {
return -1
}
n, err := sb.conn.Read(sb.sb_buf[sb.sb_start+sb.sb_size:])
if err != nil {
return 0
@ -129,6 +120,10 @@ func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
// rtmp.c +4297
// TODO replace send with golang net connection send
func C_RTMPSockBuf_Send(sb *C_RTMPSockBuf, buf []byte) int32 {
err := sb.conn.SetWriteDeadline(time.Now().Local().Add(time.Second * time.Duration(sb.timeout)))
if err != nil {
return -1
}
n, err := sb.conn.Write(buf)
if err != nil {
return -1

View File

@ -1,7 +0,0 @@
package rtmp
import "golang.org/x/sys/unix"
func setTimeval(sec int) unix.Timeval {
return unix.Timeval{Sec: int64(sec)}
}