From f91633fd70a057dee9402df36880a3af31a6bb3b Mon Sep 17 00:00:00 2001 From: simus Date: Tue, 15 Dec 2020 15:56:40 +0500 Subject: [PATCH] excepting errors on writing response, in NewFLVWriter. #132 issue --- protocol/httpflv/server.go | 4 +++- protocol/httpflv/writer.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/protocol/httpflv/server.go b/protocol/httpflv/server.go index 11cc46cc..94e52c5d 100644 --- a/protocol/httpflv/server.go +++ b/protocol/httpflv/server.go @@ -40,7 +40,9 @@ func (server *Server) Serve(l net.Listener) error { mux.HandleFunc("/streams", func(w http.ResponseWriter, r *http.Request) { server.getStream(w, r) }) - http.Serve(l, mux) + if err := http.Serve(l, mux); err != nil { + return err + } return nil } diff --git a/protocol/httpflv/writer.go b/protocol/httpflv/writer.go index 1b582223..92bab49e 100755 --- a/protocol/httpflv/writer.go +++ b/protocol/httpflv/writer.go @@ -42,15 +42,22 @@ func NewFLVWriter(app, title, url string, ctx http.ResponseWriter) *FLVWriter { packetQueue: make(chan *av.Packet, maxQueueNum), } - ret.ctx.Write([]byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09}) + if _, err := ret.ctx.Write([]byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09}); err != nil { + log.Errorf("Error on response writer") + ret.closed = true + } pio.PutI32BE(ret.buf[:4], 0) - ret.ctx.Write(ret.buf[:4]) + if _, err := ret.ctx.Write(ret.buf[:4]); err != nil { + log.Errorf("Error on response writer") + ret.closed = true + } go func() { err := ret.SendPacket() if err != nil { log.Error("SendPacket error: ", err) ret.closed = true } + }() return ret }