mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
detect when the connection with the server is closed when publishing with udp (#6)
This commit is contained in:
@@ -732,18 +732,19 @@ func (c *ConnClient) Play(u *url.URL) (*base.Response, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// LoopUDP must be called after SetupUDP() and Play(); it keeps
|
||||
// LoopUDP must be called after Play() or Record(); it keeps
|
||||
// the TCP connection open with keepalives, and returns when the TCP
|
||||
// connection closes.
|
||||
func (c *ConnClient) LoopUDP() error {
|
||||
if c.state != connClientStateReading {
|
||||
return fmt.Errorf("can be called only after a successful Play()")
|
||||
if c.state != connClientStateReading && c.state != connClientStatePublishing {
|
||||
return fmt.Errorf("can be called only after a successful Play() or Record()")
|
||||
}
|
||||
|
||||
if *c.streamProtocol != StreamProtocolUDP {
|
||||
return fmt.Errorf("stream protocol is not UDP")
|
||||
}
|
||||
|
||||
if c.state == connClientStateReading {
|
||||
readDone := make(chan error)
|
||||
go func() {
|
||||
for {
|
||||
@@ -801,6 +802,12 @@ func (c *ConnClient) LoopUDP() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// connClientStatePublishing
|
||||
c.conf.Conn.SetReadDeadline(time.Time{}) // disable deadline
|
||||
var res base.Response
|
||||
return res.Read(c.br)
|
||||
}
|
||||
|
||||
// Announce writes an ANNOUNCE request and reads a Response.
|
||||
|
@@ -161,6 +161,7 @@ func TestConnClientDialPublishUDP(t *testing.T) {
|
||||
var conn *ConnClient
|
||||
defer func() {
|
||||
conn.Close()
|
||||
conn.LoopUDP()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
|
@@ -59,6 +59,7 @@ func main() {
|
||||
// write frames to the server
|
||||
err = conn.WriteFrameTCP(track.Id, gortsplib.StreamTypeRtp, buf[:n])
|
||||
if err != nil {
|
||||
fmt.Println("connection is closed (%s)", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@@ -62,4 +62,8 @@ func main() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// wait until the connection is closed
|
||||
err = conn.LoopUDP()
|
||||
fmt.Println("connection is closed (%s)", err)
|
||||
}
|
||||
|
@@ -56,6 +56,7 @@ func main() {
|
||||
}(trackId)
|
||||
}
|
||||
|
||||
// wait until the connection is closed
|
||||
err = conn.LoopUDP()
|
||||
fmt.Println("connection is closed (%s)", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user