mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
server: allow to call server.Close() twice
This commit is contained in:
31
server.go
31
server.go
@@ -225,7 +225,7 @@ func (s *Server) Start(address string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
s.terminate = make(chan struct{})
|
||||
s.terminate = make(chan struct{}, 1)
|
||||
s.done = make(chan struct{})
|
||||
|
||||
go s.run()
|
||||
@@ -233,6 +233,22 @@ func (s *Server) Start(address string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes all the server resources and waits for the server to exit.
|
||||
func (s *Server) Close() error {
|
||||
select {
|
||||
case s.terminate <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
<-s.done
|
||||
return nil
|
||||
}
|
||||
|
||||
// Wait waits until a fatal error.
|
||||
func (s *Server) Wait() error {
|
||||
<-s.done
|
||||
return s.exitError
|
||||
}
|
||||
|
||||
func (s *Server) run() {
|
||||
s.sessions = make(map[string]*ServerSession)
|
||||
s.conns = make(map[*ServerConn]struct{})
|
||||
@@ -386,19 +402,6 @@ outer:
|
||||
close(s.done)
|
||||
}
|
||||
|
||||
// Close closes all the server resources and waits for the server to exit.
|
||||
func (s *Server) Close() error {
|
||||
close(s.terminate)
|
||||
<-s.done
|
||||
return nil
|
||||
}
|
||||
|
||||
// Wait waits until a fatal error.
|
||||
func (s *Server) Wait() error {
|
||||
<-s.done
|
||||
return s.exitError
|
||||
}
|
||||
|
||||
// StartAndWait starts the server and waits until a fatal error.
|
||||
func (s *Server) StartAndWait(address string) error {
|
||||
err := s.Start(address)
|
||||
|
Reference in New Issue
Block a user