server: add NetListener() (#833) (#934)

this allows to obtain the underlying net.Listener
This commit is contained in:
Alessandro Ros
2025-11-02 17:04:01 +01:00
committed by GitHub
parent 1214bdc17e
commit 98f0331637
2 changed files with 19 additions and 0 deletions

View File

@@ -362,6 +362,11 @@ func (s *Server) Wait() error {
return s.closeError
}
// NetListener returns the underlying net.Listener
func (s *Server) NetListener() net.Listener {
return s.tcpListener.ln
}
func (s *Server) run() {
defer s.wg.Done()

View File

@@ -240,6 +240,20 @@ func TestServerClose(t *testing.T) {
s.Close()
}
func TestServerNetListener(t *testing.T) {
s := &Server{
Handler: &testServerHandler{},
RTSPAddress: "127.0.0.1:8554",
}
err := s.Start()
require.NoError(t, err)
defer s.Close()
ln := s.NetListener()
require.Equal(t, "127.0.0.1:8554", ln.Addr().String())
}
func TestServerErrorInvalidUDPPorts(t *testing.T) {
t.Run("non consecutive", func(t *testing.T) {
s := &Server{