Add timeout to RTSP client requests

This commit is contained in:
Alexey Khit
2023-04-15 12:51:15 +03:00
parent 25dc3664fd
commit 553f5ff0d8
+7
View File
@@ -16,6 +16,8 @@ import (
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
var Timeout = time.Second * 5
func NewClient(uri string) *Conn {
return &Conn{uri: uri}
}
@@ -93,6 +95,11 @@ func (c *Conn) Request(req *tcp.Request) error {
// Do send Request and receive and process Response
func (c *Conn) Do(req *tcp.Request) (*tcp.Response, error) {
// https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
if err := c.conn.SetDeadline(time.Now().Add(Timeout)); err != nil {
return nil, err
}
if err := c.Request(req); err != nil {
return nil, err
}