make most methods thread safe (#882)

Client: Stats

ServerConn: Session, Stats

ServerSession: State, Stats, Medias, Path, Query, Stream,
SetuppedSecure, SetuppedTransport, AnnouncedDescription
This commit is contained in:
Alessandro Ros
2025-09-06 15:42:07 +02:00
committed by GitHub
parent 702cd0a70f
commit 3c2625c7cf
10 changed files with 167 additions and 59 deletions

View File

@@ -9,6 +9,7 @@ import (
gourl "net/url"
"strconv"
"strings"
"sync"
"time"
"github.com/bluenviron/gortsplib/v4/pkg/auth"
@@ -199,6 +200,7 @@ type ServerConn struct {
ctx context.Context
ctxCancel func()
propsMutex sync.RWMutex
userData interface{}
remoteAddr *net.TCPAddr
bc *bytecounter.ByteCounter
@@ -268,6 +270,9 @@ func (sc *ServerConn) UserData() interface{} {
// Session returns the associated session.
func (sc *ServerConn) Session() *ServerSession {
sc.propsMutex.RLock()
defer sc.propsMutex.RUnlock()
return sc.session
}
@@ -658,7 +663,11 @@ func (sc *ServerConn) handleRequestInSession(
}
res, session, err := sc.s.handleRequest(sreq)
sc.propsMutex.Lock()
sc.session = session
sc.propsMutex.Unlock()
return res, err
}