[alsa-devel] Alsa "short read" questions

Clemens Ladisch clemens at ladisch.de
Fri Nov 21 09:30:24 CET 2008

Pierre Vanhoucke wrote:
> 1. How is it possible to get a "short read" in blocking mode ?
> I would think that in blocking mode the control is only returned after
> the read is completed.

When an error occurs, you get the data that was read successfully before
the error.  We wouldn't want to throw away this data just because an
error happened later.  (This behaviour is for consistency with other
uses of read(); in the case of audio, throwing away some data wouldn't
actually hurt that much.)

> 2. What are the possible causes for a "short read" ?

Buffer overrun, USB device or SPDIF source unplugged, other errors.

> 3. What can be done to  avoid a "short read" ?

You cannot prevent the user from unplugging a USB device, or the
administrator from suspending your program until the buffer overruns.

> 4. How am I supposed to recover from a "short read"?

Try to read the rest of that data that you wanted to read originally,
then you'll get the error code.  (Or you'll get some data if the error
has vanished, but that is very unlikely.)

Best regards,

More information about the Alsa-devel mailing list