From 78279d44051f5b49b85f4481effc846e5ecb4340 Mon Sep 17 00:00:00 2001 From: Trek H Date: Fri, 18 Feb 2022 10:10:01 +1030 Subject: [PATCH] alsa: always return errors from ALSA.Read(), handle in Lex() --- codec/codecutil/lex.go | 5 ++++- device/alsa/alsa.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/codec/codecutil/lex.go b/codec/codecutil/lex.go index 61e71d4a..49d7344f 100644 --- a/codec/codecutil/lex.go +++ b/codec/codecutil/lex.go @@ -69,8 +69,11 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error { for { <-ticker.C off, err := src.Read(buf) - if err != nil { + // The only error that will stop the lexer is an EOF. + if err == io.EOF { return err + } else if err != nil { + continue } _, err = dst.Write(buf[:off]) if err != nil { diff --git a/device/alsa/alsa.go b/device/alsa/alsa.go index ededc6c1..e372d3a2 100644 --- a/device/alsa/alsa.go +++ b/device/alsa/alsa.go @@ -423,10 +423,10 @@ func (d *ALSA) Read(p []byte) (int, error) { return 0, err case pool.ErrTimeout: d.l.Log(logger.Debug, pkg+"pool buffer timeout") - return 0, nil + return 0, err default: d.l.Log(logger.Error, pkg+"unexpected error from Next", "error", err.Error()) - return 0, nil + return 0, err } } @@ -440,7 +440,7 @@ func (d *ALSA) Read(p []byte) (int, error) { return n, err default: d.l.Log(logger.Error, pkg+"unexpected error from Read", "error", err.Error()) - return n, nil + return n, err } } d.l.Log(logger.Debug, fmt.Sprintf("%v read %v bytes", pkg, n))