mirror of https://bitbucket.org/ausocean/av.git
revid: made rtmpSender smarter with write error handling
This commit is contained in:
parent
d18373908b
commit
88431b1357
|
@ -322,7 +322,9 @@ func (s *rtmpSender) output() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := s.conn.Write(chunk.Bytes())
|
_, 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())
|
s.log(logger.Warning, pkg+"rtmpSender: send error, restarting...", "error", err.Error())
|
||||||
err = s.restart()
|
err = s.restart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -347,7 +349,7 @@ func (s *rtmpSender) Write(d []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *rtmpSender) restart() error {
|
func (s *rtmpSender) restart() error {
|
||||||
s.Close()
|
s.close()
|
||||||
var err error
|
var err error
|
||||||
for n := 0; n < s.retries; n++ {
|
for n := 0; n < s.retries; n++ {
|
||||||
s.conn, err = rtmp.Dial(s.url, s.timeout, s.log)
|
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 {
|
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 {
|
if s.conn == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue