[alsa-devel] ALSA OSS Emulation - Read - EAGAIN Errors
hannu at opensound.com
Sat Aug 9 08:41:42 CEST 2008
Rahul Iyer wrote:
> Hi Takashi and Alexandre
> Thank you for your attention and previous replies.
> I understand EAGAIN errors can be ignored as trivial, but given there are so many of them (600 EAGAIN errors on an average for each successful call) indicates an inherent issue. And I believe it was singularly causing poor voice quality and high cpu usage.
Application should wait some time after EAGAIN before calling read/write
again. Otherwise it will spend all the available CPU time in the system
In addition the application should check how many bytes actually got
written since write() may take only the first few bytes that fit in the
buffer. The remaining bytes need to be stored by the application until
it becomes possible to write it. Most applications that use O_NONBLOCK
fail to do this which will cause badly garbled sound.
IMHO use of non-blocking I/O should be banned. It has absolutely no use.
It's far far far too difficult to use even for senior programers.
Typical "legacy" OSS applications just turn on O_NONBLOCK and then don't
do any error checking. However the application will work just fine if
O_NONBLOCK is removed from the sources. In fact OSS4 has a blacklist
feature to turn O_NONBLOCK silently off in certain popular applications
because they don't use the feature properly.
Use of poll/select is the only proper way to avoid blocking. In fact
trying to avoid blocking is completely unnecessary since audio
reads/writes will never block longer than few millisecods at time
(provided that the app uses relatively short reads/writes).
More information about the Alsa-devel