From 50884b8034764255ec6c1dfb941d568cedaecf8e Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 1 Oct 2018 11:25:16 +0930 Subject: [PATCH] rtmp: re-add recvtimeout option setting --- rtmp/socket.go | 13 +++++++++++++ rtmp/timeval_amd64.go | 7 +++++++ rtmp/timeval_arm.go | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 rtmp/timeval_amd64.go create mode 100644 rtmp/timeval_arm.go diff --git a/rtmp/socket.go b/rtmp/socket.go index 2a685110..f871cfbc 100644 --- a/rtmp/socket.go +++ b/rtmp/socket.go @@ -37,6 +37,8 @@ import ( "fmt" "log" "net" + + "golang.org/x/sys/unix" ) // int RTMP_Connect(RTMP *r, RTMPPacket* cp); @@ -66,6 +68,17 @@ 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_bSendCounter = true return C_RTMP_Connect1(r, cp) diff --git a/rtmp/timeval_amd64.go b/rtmp/timeval_amd64.go new file mode 100644 index 00000000..df7f4c4e --- /dev/null +++ b/rtmp/timeval_amd64.go @@ -0,0 +1,7 @@ +package rtmp + +import "golang.org/x/sys/unix" + +func setTimeval(sec int) unix.Timeval { + return unix.Timeval{Sec: int64(sec)} +} diff --git a/rtmp/timeval_arm.go b/rtmp/timeval_arm.go new file mode 100644 index 00000000..8bf02ed6 --- /dev/null +++ b/rtmp/timeval_arm.go @@ -0,0 +1,7 @@ +package rtmp + +import "golang.org/x/sys/unix" + +func setTimeval(sec int) unix.Timeval { + return unix.Timeval{Sec: int32(sec)} +}