Skip to content

Commit

Permalink
Use context object for socket close instead of notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
srgoni committed Apr 5, 2024
1 parent 99950c5 commit 7e80c72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion streaming/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (conn *Connection) Close() error {
// Serve starts serving data to a client, continuously feeding packets from the queue.
// An optional preamble buffer can be passed that will be sent before streaming the live payload
// (but after the HTTP response headers).
func (conn *Connection) Serve(preamble []byte) {
func (conn *Connection) Serve(preamble []byte) bool {
// set the content type (important)
conn.writer.Header().Set("Content-Type", "video/mpeg")
// a stream is always current
Expand Down
4 changes: 4 additions & 0 deletions streaming/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ func (streamer *Streamer) Stream(queue <-chan protocol.MpegTsPacket) error {
// close all downstream connections
for conn := range pool {
conn.Close()
// avoid waiting for the removal round-trip, this will make us less racy
// double deletes are safe, so nothing bad will happen when we do get the remove command later
delete(pool, request.Connection)
}
// TODO implement inhibit in the check api
case StreamerCommandAllow:
Expand Down Expand Up @@ -441,6 +444,7 @@ func (streamer *Streamer) ServeHTTP(writer http.ResponseWriter, request *http.Re
"remote", request.RemoteAddr,
)

// here's where the action happens
start := time.Now()
conn.Serve(streamer.preamble)
duration := time.Since(start)
Expand Down

0 comments on commit 7e80c72

Please sign in to comment.