snd_pcm_nonblock_mode()

Set or reset the blocking behavior of reads and writes to PCM channels

Synopsis:

#include <sys/asoundlib.h>

int snd_pcm_nonblock_mode( snd_pcm_t *handle, 
                           int nonblock );

Arguments:

handle
The handle for the PCM device, which you must have opened by calling snd_pcm_open() or snd_pcm_open_preferred() .
nonblock
If this argument is nonzero, non-blocking mode is in effect for subsequent calls to snd_pcm_read() and snd_pcm_write() .

Library:

libasound.so

Use the -l asound option to qcc to link against this library.

Description:

The snd_pcm_nonblock_mode() function sets up blocking (default) or nonblocking behavior for a handle.

Blocking mode suspends the execution of the client application when there's no room left in the buffer it's writing to, or nothing left to read when reading.

In nonblocking mode, programs aren't suspended, and the read and write functions return immediately with the number of bytes that were read or written by the driver. When used in this way, don't try to use the entire buffer after the call; instead, process the number of bytes returned and call the function again.

Returns:

Zero on success, or a negative error code.

Errors:

-EBADF
Invalid file descriptor. Your handle may be corrupt.
-EINVAL
Invalid handle.

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Caveats:

If possible, it is recommended that you design your application to call select on the PCM file descriptor, instead of using this function. Asynchronously receiving notification from the driver is much less CPU-intensive than polling it in a non-blocking loop.