mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
ServerConn: return immediately when calling Close()
This commit is contained in:
@@ -36,5 +36,6 @@ func (s *Server) Accept() (*ServerConn, error) {
|
|||||||
nconn: nconn,
|
nconn: nconn,
|
||||||
br: bufio.NewReaderSize(conn, serverReadBufferSize),
|
br: bufio.NewReaderSize(conn, serverReadBufferSize),
|
||||||
bw: bufio.NewWriterSize(conn, serverWriteBufferSize),
|
bw: bufio.NewWriterSize(conn, serverWriteBufferSize),
|
||||||
|
terminate: make(chan struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -38,11 +38,16 @@ type ServerConn struct {
|
|||||||
nextFramesEnabled bool
|
nextFramesEnabled bool
|
||||||
framesEnabled bool
|
framesEnabled bool
|
||||||
readTimeoutEnabled bool
|
readTimeoutEnabled bool
|
||||||
|
|
||||||
|
// in
|
||||||
|
terminate chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes all the connection resources.
|
// Close closes all the connection resources.
|
||||||
func (sc *ServerConn) Close() error {
|
func (sc *ServerConn) Close() error {
|
||||||
return sc.nconn.Close()
|
err := sc.nconn.Close()
|
||||||
|
close(sc.terminate)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetConn returns the underlying net.Conn.
|
// NetConn returns the underlying net.Conn.
|
||||||
@@ -201,7 +206,12 @@ func (sc *ServerConn) backgroundRead(handlers ServerConnReadHandlers, done chan
|
|||||||
// this was causing problems during unit tests.
|
// this was causing problems during unit tests.
|
||||||
if ua, ok := req.Header["User-Agent"]; ok && len(ua) == 1 &&
|
if ua, ok := req.Header["User-Agent"]; ok && len(ua) == 1 &&
|
||||||
strings.HasPrefix(ua[0], "GStreamer") {
|
strings.HasPrefix(ua[0], "GStreamer") {
|
||||||
time.Sleep(1 * time.Second)
|
t := time.NewTimer(1 * time.Second)
|
||||||
|
defer t.Stop()
|
||||||
|
select {
|
||||||
|
case <-t.C:
|
||||||
|
case <-sc.terminate:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlers.OnSetup(req, th)
|
return handlers.OnSetup(req, th)
|
||||||
|
Reference in New Issue
Block a user