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)} +}