alsa: always return errors from ALSA.Read(), handle in Lex()

This commit is contained in:
Trek H 2022-02-18 10:10:01 +10:30
parent c5c1816607
commit 78279d4405
2 changed files with 7 additions and 4 deletions

View File

@ -69,8 +69,11 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error {
for { for {
<-ticker.C <-ticker.C
off, err := src.Read(buf) 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 return err
} else if err != nil {
continue
} }
_, err = dst.Write(buf[:off]) _, err = dst.Write(buf[:off])
if err != nil { if err != nil {

View File

@ -423,10 +423,10 @@ func (d *ALSA) Read(p []byte) (int, error) {
return 0, err return 0, err
case pool.ErrTimeout: case pool.ErrTimeout:
d.l.Log(logger.Debug, pkg+"pool buffer timeout") d.l.Log(logger.Debug, pkg+"pool buffer timeout")
return 0, nil return 0, err
default: default:
d.l.Log(logger.Error, pkg+"unexpected error from Next", "error", err.Error()) 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 return n, err
default: default:
d.l.Log(logger.Error, pkg+"unexpected error from Read", "error", err.Error()) 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)) d.l.Log(logger.Debug, fmt.Sprintf("%v read %v bytes", pkg, n))