From 88431b1357cddf13bed9f0164e873dd7440b9a9c Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 15 Apr 2019 11:20:36 +0930 Subject: [PATCH] revid: made rtmpSender smarter with write error handling --- revid/senders.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/revid/senders.go b/revid/senders.go index 5f290fa2..a4aec8b3 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -322,7 +322,9 @@ func (s *rtmpSender) output() { } } _, err := s.conn.Write(chunk.Bytes()) - if err != nil { + switch err { + case nil, rtmp.ErrInvalidFlvTag: + default: s.log(logger.Warning, pkg+"rtmpSender: send error, restarting...", "error", err.Error()) err = s.restart() if err != nil { @@ -347,7 +349,7 @@ func (s *rtmpSender) Write(d []byte) (int, error) { } func (s *rtmpSender) restart() error { - s.Close() + s.close() var err error for n := 0; n < s.retries; n++ { s.conn, err = rtmp.Dial(s.url, s.timeout, s.log) @@ -363,6 +365,14 @@ func (s *rtmpSender) restart() error { } func (s *rtmpSender) Close() error { + if s.quit != nil { + close(s.quit) + } + s.wg.Wait() + return s.close() +} + +func (s *rtmpSender) close() error { if s.conn == nil { return nil }